Changeset 1504536 for doc/generic_types/evaluation/c-bench.c
- Timestamp:
- Apr 14, 2017, 5:03:43 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:
- 952d201
- Parents:
- bbe856c (diff), 3fb7f5e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/evaluation/c-bench.c
rbbe856c r1504536 7 7 8 8 _Bool* new_bool( _Bool b ) { 9 _Bool* q = malloc(sizeof(_Bool)); 9 _Bool* q = malloc(sizeof(_Bool)); /***/ 10 10 *q = b; 11 11 return q; … … 13 13 14 14 char* new_char( char c ) { 15 char* q = malloc(sizeof(char)); 15 char* q = malloc(sizeof(char)); /***/ 16 16 *q = c; 17 17 return q; … … 19 19 20 20 int* new_int( int i ) { 21 int* q = malloc(sizeof(int)); 21 int* q = malloc(sizeof(int)); /***/ 22 22 *q = i; 23 23 return q; 24 24 } 25 25 26 void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } 26 void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } /***/ 27 27 28 void* copy_char( const void* p ) { return new_char( *(const char*)p ); } 28 void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/ 29 29 30 void* copy_int( const void* p ) { return new_int( *(const int*)p ); } 30 void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/ 31 31 32 void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } 32 void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } /***/ 33 33 34 void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } 34 void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } /***/ 35 35 36 36 int cmp_bool( const void* a, const void* b ) { 37 return *(const _Bool*)a == *(const _Bool*)b ? 0 : *(const _Bool*)a < *(const _Bool*)b ? -1 : 1; 37 return *(const _Bool*)a == *(const _Bool*)b ? 0 : *(const _Bool*)a < *(const _Bool*)b ? -1 : 1; /***/ 38 38 } 39 39 40 40 int cmp_char( const void* a, const void* b ) { 41 return *(const char*)a == *(const char*)b ? 0 : *(const char*)a < *(const char*)b ? -1 : 1; 41 return *(const char*)a == *(const char*)b ? 0 : *(const char*)a < *(const char*)b ? -1 : 1; /***/ 42 42 } 43 43 44 44 int main(int argc, char** argv) { 45 FILE* out = fopen("c-out.txt", "w"); 45 46 srand(20171025); 46 47 … … 52 53 struct stack t; 53 54 TIMED( "copy_int", 54 copy_stack(&t, &s, copy_int); 55 copy_stack(&t, &s, copy_int); /***/ 55 56 ) 56 57 57 58 TIMED( "clear_int", 58 clear_stack(&s, free); 59 clear_stack(&s, free); /***/ 59 60 ) 60 61 61 62 int max = 0; 62 63 REPEAT_TIMED( "pop_int", 63 int* x = pop_stack(&t); 64 int* x = pop_stack(&t); /***/ 64 65 if ( *x > max ) { max = *x; } 65 66 free(x); 67 ) 68 print( out, "d", max, "\n" ); /***/ 69 70 REPEAT_N_TIMED( "print_int", N/2, 71 print( out, "dsds", rand(), ":", rand(), "\n" ); /***/ 66 72 ) 67 73 … … 73 79 struct stack t2; 74 80 TIMED( "copy_bool_char", 75 copy_stack(&t2, &s2, copy_pair_bool_char); 81 copy_stack(&t2, &s2, copy_pair_bool_char); /***/ 76 82 ) 77 83 78 84 TIMED( "clear_bool_char", 79 clear_stack(&s2, free_pair_bool_char); 85 clear_stack(&s2, free_pair_bool_char); /***/ 80 86 ) 81 87 82 88 struct pair* max2 = new_pair( new_bool(0), new_char('\0') ); 83 89 REPEAT_TIMED( "pop_bool_char", 84 struct pair* x = pop_stack(&t2); 85 if ( cmp_pair( x, max2, cmp_bool, cmp_char ) > 0 ) { 86 free_pair_bool_char( max2 ); 90 struct pair* x = pop_stack(&t2); /***/ 91 if ( cmp_pair( x, max2, cmp_bool, cmp_char ) > 0 ) { /***/ 92 free_pair_bool_char( max2 ); /***/ 87 93 max2 = x; 88 94 } else { 89 free_pair_bool_char( x ); 95 free_pair_bool_char( x ); /***/ 90 96 } 91 97 ) 92 free_pair_bool_char( max2 ); 98 print( out, "pbc", *max2, "\n" ); /***/ 99 free_pair_bool_char( max2 ); /***/ 93 100 94 FILE* out = fopen("c-out.txt", "w"); 95 REPEAT_TIMED( "print_int", 96 print( out, "dsds", rand(), ":", rand(), "\n" ); 101 REPEAT_N_TIMED( "print_pair", N/2, 102 struct pair p1 = ((struct pair){ new_bool(rand() & 0x1), new_char(rand() & 0x7F) }); /***/ 103 struct pair p2 = ((struct pair){ new_bool(rand() & 0x1), new_char(rand() & 0x7F) }); /***/ 104 print( out, "pbcspbcs", p1, ":", p2, "\n" ); /***/ 105 free(p1.first); free(p1.second); /***/ 106 free(p2.first); free(p2.second); /***/ 97 107 ) 98 99 REPEAT_TIMED( "print_pair", 100 struct pair p1 = ((struct pair){ new_bool(rand() & 0x1), new_char(rand() & 0x7F) }); 101 struct pair p2 = ((struct pair){ new_bool(rand() & 0x1), new_char(rand() & 0x7F) }); 102 print( out, "pbcspbcs", p1, ":", p2, "\n" ); 103 free(p1.first); free(p1.second); 104 free(p2.first); free(p2.second); 105 ) 108 106 109 fclose(out); 107 110 }
Note: See TracChangeset
for help on using the changeset viewer.