Ignore:
Timestamp:
Apr 15, 2017, 7:09:59 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
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
Message:

Minor cleanup, also filled in benchmark source appendix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/evaluation/c-bench.c

    r308880c ra381b46  
    2525
    2626void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); } /***/
    27 
    2827void* copy_char( const void* p ) { return new_char( *(const char*)p ); } /***/
    29 
    3028void* copy_int( const void* p ) { return new_int( *(const int*)p ); } /***/
    31 
    3229void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); } /***/
    33 
    3430void free_pair_bool_char( void* p ) { free_pair( p, free, free ); } /***/
    3531
    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; /***/
     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;
    3834}
    3935
     
    4440int main(int argc, char** argv) {
    4541        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 
    6242        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); /***/ )
    6347        REPEAT_TIMED( "pop_int",
    6448                int* x = pop_stack(&t); /***/
    6549                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" ); /***/ )
    8752
    8853        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); /***/ )
    8960        REPEAT_TIMED( "pop_bool_char",
    9061                struct pair* x = pop_stack(&t2); /***/
     
    9465                } else {
    9566                        free_pair_bool_char( x ); /***/
    96                 }
    97         )
    98         print( out, "pbc", *max2, "\n" ); /***/
    99         free_pair_bool_char( max2 ); /***/
    100 
     67                } )
    10168        REPEAT_N_TIMED( "print_pair", N/2,
    10269                struct pair p1 = ((struct pair){ new_bool(rand() & 0x1), new_char(rand() & 0x7F) }); /***/
     
    10471                print( out, "pbcspbcs", p1, ":", p2, "\n" ); /***/
    10572                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 ); /***/
    10975        fclose(out);
    11076}
Note: See TracChangeset for help on using the changeset viewer.