Ignore:
Timestamp:
Apr 19, 2017, 10:15:45 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
cd348e7
Parents:
221c2de (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    r221c2de r154fdc8  
     1#include <stdio.h>
    12#include <stdlib.h>
    23#include "bench.h"
     4#include "c-pair.h"
    35#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}
    439
    540int 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;
    744
    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" ); /***/ )
    953
    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;
    1557
    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);
    1773}
Note: See TracChangeset for help on using the changeset viewer.