| [604e76d] | 1 | #include <stdio.h> | 
|---|
|  | 2 | #include <stdlib.h> | 
|---|
|  | 3 | #include "bench.h" | 
|---|
|  | 4 | #include "c-pair.h" | 
|---|
|  | 5 | #include "c-stack.h" | 
|---|
|  | 6 |  | 
|---|
|  | 7 | char* new_char( char c ) { | 
|---|
|  | 8 | char* q = malloc(sizeof(char)); /***/ | 
|---|
|  | 9 | *q = c; | 
|---|
|  | 10 | return q; | 
|---|
|  | 11 | } | 
|---|
|  | 12 |  | 
|---|
| [fb2ce27] | 13 | short* new_short( short s ) { | 
|---|
|  | 14 | short* q = malloc(sizeof(short)); /***/ | 
|---|
|  | 15 | *q = s; | 
|---|
|  | 16 | return q; | 
|---|
|  | 17 | } | 
|---|
|  | 18 |  | 
|---|
| [604e76d] | 19 | int* new_int( int i ) { | 
|---|
|  | 20 | int* q = malloc(sizeof(int)); /***/ | 
|---|
|  | 21 | *q = i; | 
|---|
|  | 22 | return q; | 
|---|
|  | 23 | } | 
|---|
|  | 24 |  | 
|---|
|  | 25 | void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/ | 
|---|
| [fb2ce27] | 26 | void* copy_short( const void* p ) { return new_short( *(const short*)p ); } /***/ | 
|---|
| [604e76d] | 27 | void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/ | 
|---|
| [fb2ce27] | 28 | void* copy_pair_short_char( const void* p ) { return copy_pair( p, copy_short, copy_char ); } /***/ | 
|---|
|  | 29 | void free_pair_short_char( void* p ) { free_pair( p, free, free ); } /***/ | 
|---|
| [604e76d] | 30 |  | 
|---|
|  | 31 | int 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 |  | 
|---|
| [fb2ce27] | 35 | int 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 |  | 
|---|
| [604e76d] | 39 | int 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 |  | 
|---|
| [fb2ce27] | 51 | struct pair * maxp = new_pair( new_short(0), new_char('\0') ), | 
|---|
|  | 52 | * valp = new_pair( new_short(42), new_char('a') ); | 
|---|
| [604e76d] | 53 | struct stack sp = new_stack(), tp; | 
|---|
|  | 54 |  | 
|---|
| [fb2ce27] | 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 ); /***/ ) | 
|---|
| [604e76d] | 58 | REPEAT_TIMED( "pop_pair", N, | 
|---|
|  | 59 | struct pair * xp = pop_stack( &tp ); | 
|---|
| [fb2ce27] | 60 | if ( cmp_pair( xp, maxp, cmp_short, cmp_char /***/ ) > 0 ) { | 
|---|
|  | 61 | free_pair_short_char( maxp ); /***/ | 
|---|
| [604e76d] | 62 | maxp = xp; | 
|---|
|  | 63 | } else { | 
|---|
| [fb2ce27] | 64 | free_pair_short_char( xp ); /***/ | 
|---|
| [604e76d] | 65 | } ) | 
|---|
| [fb2ce27] | 66 | free_pair_short_char( maxp ); /***/ | 
|---|
|  | 67 | free_pair_short_char( valp ); /***/ | 
|---|
| [604e76d] | 68 | } | 
|---|