- Timestamp:
- Apr 7, 2017, 2:32:03 PM (8 years ago)
- 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
- Location:
- doc/generic_types/evaluation
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/evaluation/Makefile
r4cfcf41 r122aecd 1 1 CFA = my-cfa 2 2 DEPFLAGS = -MMD -MP 3 OPT = -O2 4 CFLAGS = $(OPT) 5 CXXFLAGS = $(OPT) 3 6 4 7 .PHONY: all clean distclean bench 5 8 6 all: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench9 all: c-bench cpp-bench cfa-bench 7 10 8 11 # rewrite object generation to auto-determine deps … … 13 16 c-%.o : c-%.c 14 17 c-%.o : c-%.c c-%.d 15 $(COMPILE.c) -O0$(OUTPUT_OPTION) -c $<18 $(COMPILE.c) $(OUTPUT_OPTION) -c $< 16 19 17 20 cpp-%.o : cpp-%.cpp 18 21 cpp-%.o : cpp-%.cpp cpp-%.d 19 $(COMPILE.cpp) -O0$(OUTPUT_OPTION) -c $<22 $(COMPILE.cpp) $(OUTPUT_OPTION) -c $< 20 23 21 24 cfa-%.o : cfa-%.c 22 25 cfa-%.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 $< 36 27 37 28 COBJS = c-stack.o 38 29 CPPOBJS = 39 30 CFAOBJS = cfa-stack.o 40 C2OBJS = $(patsubst c-%,c2-%, $(COBJS))41 CPP2OBJS = $(patsubst cpp-%,cpp2-%, $(CPPOBJS))42 CFA2OBJS = $(patsubst cfa-%,cfa2-%, $(CFAOBJS))43 31 44 32 c-bench: c-bench.c c-bench.d $(COBJS) 45 $(COMPILE.c) - O0 -o $@ $< $(COBJS) $(LDFLAGS)33 $(COMPILE.c) -o $@ $< $(COBJS) $(LDFLAGS) 46 34 47 35 cpp-bench: cpp-bench.cpp cpp-bench.d $(CPPOBJS) 48 $(COMPILE.cpp) - O0 -o $@ $< $(CPPOBJS) $(LDFLAGS)36 $(COMPILE.cpp) -o $@ $< $(CPPOBJS) $(LDFLAGS) 49 37 50 38 cfa-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) 61 40 62 41 clean: … … 64 43 -rm $(CPPOBJS) cpp-bench 65 44 -rm $(CFAOBJS) cfa-bench 66 -rm $(C2OBJS) c2-bench67 -rm $(CPP2OBJS) cpp2-bench68 -rm $(CFA2OBJS) cfa2-bench69 45 70 46 distclean: clean … … 73 49 -rm $(CFAOBJS:.o=.d) cfa-bench.d 74 50 75 bench: c-bench cpp-bench cfa-bench c2-bench cpp2-bench cfa2-bench51 bench: c-bench cpp-bench cfa-bench 76 52 @echo '## C ##' 77 53 @./c-bench … … 80 56 @echo '## Cforall ##' 81 57 @./cfa-bench 82 @echo '## C -O2 ##'83 @./c2-bench84 @echo '## C++ -O2 ##'85 @./cpp2-bench86 @echo '## Cforall -O2 ##'87 @./cfa2-bench88 58 89 59 # so make doesn't fail without dependency files -
doc/generic_types/evaluation/bench.h
r4cfcf41 r122aecd 2 2 #include <time.h> 3 3 4 #define N 200000000 4 // #define N 50000000 5 #define N 5 6 5 7 6 8 long ms_between(clock_t start, clock_t end) { -
doc/generic_types/evaluation/c-bench.c
r4cfcf41 r122aecd 2 2 #include "bench.h" 3 3 #include "c-stack.h" 4 5 void* copy_int( void* p ) { 6 int* q = malloc(sizeof(int)); 7 *q = *(int*)p; 8 return q; 9 } 4 10 5 11 int main(int argc, char** argv) { … … 7 13 8 14 struct stack s = new_stack(); 9 10 15 REPEAT_TIMED( "push_int", 11 16 int* x = malloc(sizeof(int)); … … 14 19 ) 15 20 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 ) 17 36 } -
doc/generic_types/evaluation/c-stack.c
r4cfcf41 r122aecd 9 9 struct stack new_stack() { 10 10 return (struct stack){ NULL }; 11 } 12 13 void 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; 11 23 } 12 24 -
doc/generic_types/evaluation/c-stack.h
r4cfcf41 r122aecd 7 7 struct stack new_stack(); 8 8 9 void copy_stack(struct stack* dst, struct stack* src, void* (*copy)(void*)); 10 9 11 void clear_stack(struct stack* s); 10 12 -
doc/generic_types/evaluation/cfa-bench.c
r4cfcf41 r122aecd 7 7 8 8 stack(int) s; 9 10 9 REPEAT_TIMED( "push_int", 11 10 push( &s, rand() ); 12 11 ) 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 ) 13 26 } -
doc/generic_types/evaluation/cfa-stack.c
r4cfcf41 r122aecd 8 8 9 9 forall(otype T) void ?{}(stack(T)* s) { 10 ?{}( &s->head, 0 ); 10 (&s->head){ 0 }; 11 } 12 13 forall(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 25 forall(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; 11 30 } 12 31 13 32 forall(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); 20 34 } 21 35 … … 35 49 return x; 36 50 } 51 52 forall(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 7 7 forall(otype T) void ?{}(stack(T)* s); 8 8 9 forall(otype T) void ?{}(stack(T)* s, stack(T) t); 10 11 forall(otype T) stack(T) ?=?(stack(T)* s, stack(T) t); 12 9 13 forall(otype T) void ^?{}(stack(T)* s); 10 14 … … 14 18 15 19 forall(otype T) T pop(stack(T)* s); 20 21 forall(otype T) void clear(stack(T)* s); -
doc/generic_types/evaluation/cpp-bench.cpp
r4cfcf41 r122aecd 7 7 8 8 stack<int> s; 9 10 9 REPEAT_TIMED( "push_int", 11 10 s.push( rand() ); 12 11 ) 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 ) 13 26 } -
doc/generic_types/evaluation/cpp-stack.h
r4cfcf41 r122aecd 6 6 node* next; 7 7 8 node( T& v ) : value(v), next(nullptr) {} 8 9 node( T&& v, node* n ) : value(std::move(v)), next(n) {} 9 10 }; … … 11 12 node* head; 12 13 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 13 25 public: 14 stack() : head(nullptr) {} 15 16 ~stack() { 26 void clear() { 17 27 node* next = head; 18 28 while ( next ) { … … 21 31 delete crnt; 22 32 } 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; 23 55 } 24 56
Note: See TracChangeset
for help on using the changeset viewer.