source: doc/papers/general/evaluation/c-bench.c @ f86c8e5

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f86c8e5 was fb2ce27, checked in by Aaron Moss <a3moss@…>, 6 years ago

Update all benchmarks to match new CFA

  • Property mode set to 100644
File size: 2.1 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
7char* new_char( char c ) {
8        char* q = malloc(sizeof(char)); /***/
9        *q = c;
10        return q;
11}
12
13short* new_short( short s ) {
14        short* q = malloc(sizeof(short)); /***/
15        *q = s;
16        return q;
17}
18
19int* new_int( int i ) {
20        int* q = malloc(sizeof(int)); /***/
21        *q = i;
22        return q;
23}
24
25void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/
26void* copy_short( const void* p ) { return new_short( *(const short*)p ); } /***/
27void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/
28void* copy_pair_short_char( const void* p ) { return copy_pair( p, copy_short, copy_char ); } /***/
29void free_pair_short_char( void* p ) { free_pair( p, free, free ); } /***/
30
31int cmp_char( const void* a, const void* b ) { /***/
32        return *(const char*)a == *(const char*)b ? 0 : *(const char*)a < *(const char*)b ? -1 : 1;
33}
34
35int cmp_short( const void* a, const void* b ) { /***/
36        return *(const short*)a == *(const short*)b ? 0 : *(const short*)a < *(const short*)b ? -1 : 1; 
37}
38
39int main(int argc, char** argv) {
40        int maxi = 0, vali = 42;
41        struct stack si = new_stack(), ti;
42
43        REPEAT_TIMED( "push_int", N, push_stack( &si, new_int( vali ) ); )
44        TIMED( "copy_int",      copy_stack( &ti, &si, copy_int ); /***/ )
45        TIMED( "clear_int", clear_stack( &si, free ); /***/ )
46        REPEAT_TIMED( "pop_int", N, 
47                int* xi = pop_stack( &ti );
48                if ( *xi > maxi ) { maxi = *xi; }
49                free(xi); )
50
51        struct pair * maxp = new_pair( new_short(0), new_char('\0') ),
52                * valp = new_pair( new_short(42), new_char('a') );
53        struct stack sp = new_stack(), tp;
54
55        REPEAT_TIMED( "push_pair", N, push_stack( &sp, copy_pair_short_char( valp ) ); )
56        TIMED( "copy_pair", copy_stack( &tp, &sp, copy_pair_short_char ); /***/ )
57        TIMED( "clear_pair", clear_stack( &sp, free_pair_short_char ); /***/ )
58        REPEAT_TIMED( "pop_pair", N, 
59                struct pair * xp = pop_stack( &tp );
60                if ( cmp_pair( xp, maxp, cmp_short, cmp_char /***/ ) > 0 ) {
61                        free_pair_short_char( maxp ); /***/
62                        maxp = xp;
63                } else {
64                        free_pair_short_char( xp ); /***/
65                } )
66        free_pair_short_char( maxp ); /***/
67        free_pair_short_char( valp ); /***/
68}
Note: See TracBrowser for help on using the repository browser.