source: doc/papers/OOPSLA17/evaluation/c-bench.c@ c71b256

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since c71b256 was f4e3419d, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

restructure paper documents

  • Property mode set to 100644
File size: 2.4 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include "bench.h"
4#include "c-pair.h"
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
14char* new_char( char c ) {
15 char* q = malloc(sizeof(char)); /***/
16 *q = c;
17 return q;
18}
19
20int* new_int( int i ) {
21 int* q = malloc(sizeof(int)); /***/
22 *q = i;
23 return q;
24}
25
26void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } /***/
27void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/
28void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/
29void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } /***/
30void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } /***/
31
32int 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
36int 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}
39
40int main(int argc, char** argv) {
41 FILE * out = fopen("/dev/null", "w");
42 int maxi = 0, vali = 42;
43 struct stack si = new_stack(), ti;
44
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" ); /***/ )
53
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;
57
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);
73}
Note: See TracBrowser for help on using the repository browser.