Changeset a381b46 for doc/generic_types/evaluation/c-bench.c
- Timestamp:
- Apr 15, 2017, 7:09:59 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:
- c57d1935
- Parents:
- 308880c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/evaluation/c-bench.c
r308880c ra381b46 25 25 26 26 void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } /***/ 27 28 27 void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/ 29 30 28 void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/ 31 32 29 void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } /***/ 33 34 30 void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } /***/ 35 31 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; /***/32 int cmp_bool( const void* a, const void* b ) { /***/ 33 return *(const _Bool*)a == *(const _Bool*)b ? 0 : *(const _Bool*)a < *(const _Bool*)b ? -1 : 1; 38 34 } 39 35 … … 44 40 int main(int argc, char** argv) { 45 41 FILE* out = fopen("c-out.txt", "w"); 46 srand(20171025);47 48 struct stack s = new_stack();49 REPEAT_TIMED( "push_int",50 push_stack(&s, new_int( rand() ));51 )52 53 struct stack t;54 TIMED( "copy_int",55 copy_stack(&t, &s, copy_int); /***/56 )57 58 TIMED( "clear_int",59 clear_stack(&s, free); /***/60 )61 62 42 int max = 0; 43 struct stack s = new_stack(), t; 44 REPEAT_TIMED( "push_int", push_stack(&s, new_int( _i )); ) 45 TIMED( "copy_int", copy_stack(&t, &s, copy_int); /***/ ) 46 TIMED( "clear_int", clear_stack(&s, free); /***/ ) 63 47 REPEAT_TIMED( "pop_int", 64 48 int* x = pop_stack(&t); /***/ 65 49 if ( *x > max ) { max = *x; } 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" ); /***/ 72 ) 73 74 struct stack s2 = new_stack(); 75 REPEAT_TIMED( "push_bool_char", 76 push_stack(&s2, new_pair( new_bool( rand() & 0x1 ), new_char( rand() & 0x7F ) )); 77 ) 78 79 struct stack t2; 80 TIMED( "copy_bool_char", 81 copy_stack(&t2, &s2, copy_pair_bool_char); /***/ 82 ) 83 84 TIMED( "clear_bool_char", 85 clear_stack(&s2, free_pair_bool_char); /***/ 86 ) 50 free(x); ) 51 REPEAT_N_TIMED( "print_int", N/2, print( out, "dsds", _i, ":", _i, "\n" ); /***/ ) 87 52 88 53 struct pair* max2 = new_pair( new_bool(0), new_char('\0') ); 54 struct stack s2 = new_stack(), t2; 55 56 REPEAT_TIMED( "push_bool_char", 57 push_stack(&s2, new_pair( new_bool( _i & 0x1 ), new_char( _i & 0x7F ) )); ) 58 TIMED( "copy_bool_char", copy_stack(&t2, &s2, copy_pair_bool_char); /***/ ) 59 TIMED( "clear_bool_char", clear_stack(&s2, free_pair_bool_char); /***/ ) 89 60 REPEAT_TIMED( "pop_bool_char", 90 61 struct pair* x = pop_stack(&t2); /***/ … … 94 65 } else { 95 66 free_pair_bool_char( x ); /***/ 96 } 97 ) 98 print( out, "pbc", *max2, "\n" ); /***/ 99 free_pair_bool_char( max2 ); /***/ 100 67 } ) 101 68 REPEAT_N_TIMED( "print_pair", N/2, 102 69 struct pair p1 = ((struct pair){ new_bool(rand() & 0x1), new_char(rand() & 0x7F) }); /***/ … … 104 71 print( out, "pbcspbcs", p1, ":", p2, "\n" ); /***/ 105 72 free(p1.first); free(p1.second); /***/ 106 free(p2.first); free(p2.second); /***/ 107 ) 108 73 free(p2.first); free(p2.second); /***/ ) 74 free_pair_bool_char( max2 ); /***/ 109 75 fclose(out); 110 76 }
Note: See TracChangeset
for help on using the changeset viewer.