Changeset 154fdc8 for doc/generic_types/evaluation/c-bench.c
- Timestamp:
- Apr 19, 2017, 10:15:45 AM (7 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:
- cd348e7
- Parents:
- 221c2de7 (diff), de4ce0e (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
r221c2de7 r154fdc8 1 #include <stdio.h> 1 2 #include <stdlib.h> 2 3 #include "bench.h" 4 #include "c-pair.h" 3 5 #include "c-stack.h" 6 #include "c-print.h" 7 8 _Bool* new_bool( _Bool b ) { 9 _Bool* q = malloc(sizeof(_Bool)); /***/ 10 *q = b; 11 return q; 12 } 13 14 char* new_char( char c ) { 15 char* q = malloc(sizeof(char)); /***/ 16 *q = c; 17 return q; 18 } 19 20 int* new_int( int i ) { 21 int* q = malloc(sizeof(int)); /***/ 22 *q = i; 23 return q; 24 } 25 26 void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } /***/ 27 void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/ 28 void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/ 29 void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } /***/ 30 void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } /***/ 31 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; 34 } 35 36 int cmp_char( const void* a, const void* b ) { /***/ 37 return *(const char*)a == *(const char*)b ? 0 : *(const char*)a < *(const char*)b ? -1 : 1; 38 } 4 39 5 40 int main(int argc, char** argv) { 6 srand(20171025); 41 FILE * out = fopen("c-out.txt", "w"); 42 int maxi = 0, vali = 42; 43 struct stack si = new_stack(), ti; 7 44 8 struct stack s = new_stack(); 45 REPEAT_TIMED( "push_int", N, push_stack( &si, new_int( vali ) ); ) 46 TIMED( "copy_int", copy_stack( &ti, &si, copy_int ); /***/ ) 47 TIMED( "clear_int", clear_stack( &si, free ); /***/ ) 48 REPEAT_TIMED( "pop_int", N, 49 int* xi = pop_stack( &ti ); 50 if ( *xi > maxi ) { maxi = *xi; } 51 free(xi); ) 52 REPEAT_TIMED( "print_int", N/2, print( out, "dsds", vali, ":", vali, "\n" ); /***/ ) 9 53 10 REPEAT_TIMED( "push_int", 11 int* x = malloc(sizeof(int)); 12 *x = rand(); 13 push_stack(&s, x); 14 ) 54 struct pair * maxp = new_pair( new_bool(0), new_char('\0') ), 55 * valp = new_pair( new_bool(1), new_char('a') ); 56 struct stack sp = new_stack(), tp; 15 57 16 clear_stack(&s); 58 REPEAT_TIMED( "push_pair", N, push_stack( &sp, copy_pair_bool_char( valp ) ); ) 59 TIMED( "copy_pair", copy_stack( &tp, &sp, copy_pair_bool_char ); /***/ ) 60 TIMED( "clear_pair", clear_stack( &sp, free_pair_bool_char ); /***/ ) 61 REPEAT_TIMED( "pop_pair", N, 62 struct pair * xp = pop_stack( &tp ); 63 if ( cmp_pair( xp, maxp, cmp_bool, cmp_char /***/ ) > 0 ) { 64 free_pair_bool_char( maxp ); /***/ 65 maxp = xp; 66 } else { 67 free_pair_bool_char( xp ); /***/ 68 } ) 69 REPEAT_TIMED( "print_pair", N/2, print( out, "pbcspbcs", *valp, ":", *valp, "\n" ); /***/ ) 70 free_pair_bool_char( maxp ); /***/ 71 free_pair_bool_char( valp ); /***/ 72 fclose(out); 17 73 }
Note: See TracChangeset
for help on using the changeset viewer.