Changeset 122aecd for doc


Ignore:
Timestamp:
Apr 7, 2017, 2:32:03 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
3a48e283
Parents:
4cfcf41
Message:

Expand benchmarks

Location:
doc/generic_types/evaluation
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/evaluation/Makefile

    r4cfcf41 r122aecd  
    11CFA = my-cfa
    22DEPFLAGS = -MMD -MP
     3OPT = -O2
     4CFLAGS = $(OPT)
     5CXXFLAGS = $(OPT)
    36
    47.PHONY: all clean distclean bench
    58
    6 all: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench
     9all: c-bench cpp-bench cfa-bench
    710
    811# rewrite object generation to auto-determine deps
     
    1316c-%.o : c-%.c
    1417c-%.o : c-%.c c-%.d
    15         $(COMPILE.c) -O0 $(OUTPUT_OPTION) -c $<
     18        $(COMPILE.c) $(OUTPUT_OPTION) -c $<
    1619
    1720cpp-%.o : cpp-%.cpp
    1821cpp-%.o : cpp-%.cpp cpp-%.d
    19         $(COMPILE.cpp) -O0 $(OUTPUT_OPTION) -c $<
     22        $(COMPILE.cpp) $(OUTPUT_OPTION) -c $<
    2023
    2124cfa-%.o : cfa-%.c
    2225cfa-%.o : cfa-%.c cfa-%.d
    23         $(COMPILE.cfa) -O0 $(OUTPUT_OPTION) -c $<
    24 
    25 c2-%.o : c-%.c
    26 c2-%.o : c-%.c c-%.d
    27         $(COMPILE.c) -O2 $(OUTPUT_OPTION) -c $<
    28 
    29 cpp2-%.o : cpp-%.cpp
    30 cpp2-%.o : cpp-%.cpp cpp-%.d
    31         $(COMPILE.cpp) -O2 $(OUTPUT_OPTION) -c $<
    32 
    33 cfa2-%.o : cfa-%.c
    34 cfa2-%.o : cfa-%.c cfa-%.d
    35         $(COMPILE.cfa) -O2 $(OUTPUT_OPTION) -c $<
     26        $(COMPILE.cfa) $(OUTPUT_OPTION) -c $<
    3627
    3728COBJS = c-stack.o
    3829CPPOBJS =
    3930CFAOBJS = cfa-stack.o
    40 C2OBJS = $(patsubst c-%,c2-%, $(COBJS))
    41 CPP2OBJS = $(patsubst cpp-%,cpp2-%, $(CPPOBJS))
    42 CFA2OBJS = $(patsubst cfa-%,cfa2-%, $(CFAOBJS))
    4331
    4432c-bench: c-bench.c c-bench.d $(COBJS)
    45         $(COMPILE.c) -O0 -o $@ $< $(COBJS) $(LDFLAGS)
     33        $(COMPILE.c) -o $@ $< $(COBJS) $(LDFLAGS)
    4634
    4735cpp-bench: cpp-bench.cpp cpp-bench.d $(CPPOBJS)
    48         $(COMPILE.cpp) -O0 -o $@ $< $(CPPOBJS) $(LDFLAGS)
     36        $(COMPILE.cpp) -o $@ $< $(CPPOBJS) $(LDFLAGS)
    4937
    5038cfa-bench: cfa-bench.c cfa-bench.d $(CFAOBJS)
    51         $(COMPILE.cfa) -O0 -o $@ $< $(CFAOBJS) $(LDFLAGS)
    52 
    53 c2-bench: c-bench.c c-bench.d $(C2OBJS)
    54         $(COMPILE.c) -O2 -o $@ $< $(C2OBJS) $(LDFLAGS)
    55 
    56 cpp2-bench: cpp-bench.cpp cpp-bench.d $(CPP2OBJS)
    57         $(COMPILE.cpp) -O2 -o $@ $< $(CPP2OBJS) $(LDFLAGS)
    58 
    59 cfa2-bench: cfa-bench.c cfa-bench.d $(CFA2OBJS)
    60         $(COMPILE.cfa) -O2 -o $@ $< $(CFA2OBJS) $(LDFLAGS)
     39        $(COMPILE.cfa) -o $@ $< $(CFAOBJS) $(LDFLAGS)
    6140
    6241clean:
     
    6443        -rm $(CPPOBJS) cpp-bench
    6544        -rm $(CFAOBJS) cfa-bench
    66         -rm $(C2OBJS) c2-bench
    67         -rm $(CPP2OBJS) cpp2-bench
    68         -rm $(CFA2OBJS) cfa2-bench
    6945
    7046distclean: clean
     
    7349        -rm $(CFAOBJS:.o=.d) cfa-bench.d
    7450
    75 bench: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench
     51bench: c-bench cpp-bench cfa-bench
    7652        @echo '## C ##'
    7753        @./c-bench
     
    8056        @echo '## Cforall ##'
    8157        @./cfa-bench
    82         @echo '## C -O2 ##'
    83         @./c2-bench
    84         @echo '## C++ -O2 ##'
    85         @./cpp2-bench
    86         @echo '## Cforall -O2 ##'
    87         @./cfa2-bench
    8858
    8959# so make doesn't fail without dependency files
  • doc/generic_types/evaluation/bench.h

    r4cfcf41 r122aecd  
    22#include <time.h>
    33
    4 #define N 200000000
     4 // #define N 50000000
     5 #define N 5
     6
    57
    68long ms_between(clock_t start, clock_t end) {
  • doc/generic_types/evaluation/c-bench.c

    r4cfcf41 r122aecd  
    22#include "bench.h"
    33#include "c-stack.h"
     4
     5void* copy_int( void* p ) {
     6        int* q = malloc(sizeof(int));
     7        *q = *(int*)p;
     8        return q;
     9}
    410
    511int main(int argc, char** argv) {
     
    713
    814        struct stack s = new_stack();
    9 
    1015        REPEAT_TIMED( "push_int",
    1116                int* x = malloc(sizeof(int));
     
    1419        )
    1520
    16         clear_stack(&s);
     21        struct stack t;
     22        TIMED( "copy_int",
     23                copy_stack(&t, &s, copy_int);
     24        )
     25
     26        TIMED( "clear_int",
     27                clear_stack(&s);
     28        )
     29
     30        int sum;
     31        REPEAT_TIMED( "pop_int",
     32                int* x = pop_stack(&t);
     33                sum += *x;
     34                free(x);
     35        )
    1736}
  • doc/generic_types/evaluation/c-stack.c

    r4cfcf41 r122aecd  
    99struct stack new_stack() {
    1010        return (struct stack){ NULL };
     11}
     12
     13void copy_stack(struct stack* s, struct stack* t, void* (*copy)(void*)) {
     14        struct stack_node** crnt = &s->head;
     15        struct stack_node* next = t->head;
     16        while ( next ) {
     17                *crnt = malloc(sizeof(struct stack_node));
     18                **crnt = (struct stack_node){ copy(next->value) };
     19                crnt = &(*crnt)->next;
     20                next = next->next;
     21        }
     22        *crnt = 0;
    1123}
    1224
  • doc/generic_types/evaluation/c-stack.h

    r4cfcf41 r122aecd  
    77struct stack new_stack();
    88
     9void copy_stack(struct stack* dst, struct stack* src, void* (*copy)(void*));
     10
    911void clear_stack(struct stack* s);
    1012
  • doc/generic_types/evaluation/cfa-bench.c

    r4cfcf41 r122aecd  
    77
    88        stack(int) s;
    9 
    109        REPEAT_TIMED( "push_int",
    1110                push( &s, rand() );
    1211        )
     12
     13        stack(int) t;
     14        TIMED( "copy_int",
     15                t = s;
     16        )
     17
     18        TIMED( "clear_int",
     19                clear( &s );
     20        )
     21
     22        int sum;
     23        REPEAT_TIMED( "pop_int",
     24                sum += pop( &t );
     25        )
    1326}
  • doc/generic_types/evaluation/cfa-stack.c

    r4cfcf41 r122aecd  
    88
    99forall(otype T) void ?{}(stack(T)* s) {
    10         ?{}( &s->head, 0 );
     10        (&s->head){ 0 };
     11}
     12
     13forall(otype T) void ?{}(stack(T)* s, stack(T) t) {
     14        stack_node(T)** crnt = &s->head;
     15        stack_node(T)* next = t.head;
     16        while ( next ) {
     17                *crnt = ((stack_node(T)*)malloc()){ next->value };
     18                stack_node(T)* acrnt = *crnt;
     19                crnt = &acrnt->next;
     20                next = next->next;
     21        }
     22        *crnt = 0;
     23}
     24
     25forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t) {
     26        if ( s->head == t.head ) return *s;
     27        clear(s);
     28        s{ t };
     29        return *s;
    1130}
    1231
    1332forall(otype T) void ^?{}(stack(T)* s) {
    14         stack_node(T)* next = s->head;
    15         while ( next ) {
    16                 stack_node(T)* crnt = next;
    17                 next = crnt->next;
    18                 delete(crnt);
    19         }
     33        clear(s);
    2034}
    2135
     
    3549        return x;
    3650}
     51
     52forall(otype T) void clear(stack(T)* s) {
     53        stack_node(T)* next = s->head;
     54        while ( next ) {
     55                stack_node(T)* crnt = next;
     56                next = crnt->next;
     57                delete(crnt);
     58        }
     59}
  • doc/generic_types/evaluation/cfa-stack.h

    r4cfcf41 r122aecd  
    77forall(otype T) void ?{}(stack(T)* s);
    88
     9forall(otype T) void ?{}(stack(T)* s, stack(T) t);
     10
     11forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t);
     12
    913forall(otype T) void ^?{}(stack(T)* s);
    1014
     
    1418
    1519forall(otype T) T pop(stack(T)* s);
     20
     21forall(otype T) void clear(stack(T)* s);
  • doc/generic_types/evaluation/cpp-bench.cpp

    r4cfcf41 r122aecd  
    77
    88        stack<int> s;
    9 
    109        REPEAT_TIMED( "push_int",
    1110                s.push( rand() );
    1211        )
     12
     13        stack<int> t;
     14        TIMED( "copy_int",
     15                t = s;
     16        )
     17
     18        TIMED( "clear_int",
     19                s.clear();
     20        )
     21
     22        int sum;
     23        REPEAT_TIMED( "pop_int",
     24                sum += t.pop();
     25        )
    1326}
  • doc/generic_types/evaluation/cpp-stack.h

    r4cfcf41 r122aecd  
    66                node* next;
    77
     8                node( T& v ) : value(v), next(nullptr) {}
    89                node( T&& v, node* n ) : value(std::move(v)), next(n) {}
    910        };
     
    1112        node* head;
    1213
     14        void copy(const stack<T>& o) {
     15                node** crnt = &head;
     16                node* next = o.head;
     17                while ( next ) {
     18                        *crnt = new node{ next->value };
     19                        crnt = &(*crnt)->next;
     20                        next = next->next;
     21                }
     22                *crnt = nullptr;
     23        }
     24
    1325public:
    14         stack() : head(nullptr) {}
    15 
    16         ~stack() {
     26        void clear() {
    1727                node* next = head;
    1828                while ( next ) {
     
    2131                        delete crnt;
    2232                }
     33        }
     34
     35        stack() : head(nullptr) {}
     36
     37        stack(const stack<T>& o) { copy(o); }
     38
     39        stack(stack<T>&& o) : head(o.head) { o.head = nullptr; }
     40
     41        ~stack() { clear(); }
     42
     43        stack& operator= (const stack<T>& o) {
     44                if ( this == &o ) return *this;
     45                clear();
     46                copy(o);
     47                return *this;if ( this == &o ) return *this;
     48        }
     49
     50        stack& operator= (stack<T>&& o) {
     51                if ( this == &o ) return *this;
     52                head = o.head;
     53                o.head = nullptr;
     54                return *this;
    2355        }
    2456
Note: See TracChangeset for help on using the changeset viewer.