Ignore:
Timestamp:
Apr 11, 2017, 6:35:59 PM (7 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
3720bf8f
Parents:
f674479 (diff), 4f57930 (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 plg2:software/cfa/cfa-cc

File:
1 edited

Legend:

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

    rf674479 rda1c772  
    11#include <stdlib.h>
    22#include "bench.h"
     3#include "c-pair.h"
    34#include "c-stack.h"
    45
    5 void* copy_int( void* p ) {
     6_Bool* new_bool( _Bool b ) {
     7        _Bool* q = malloc(sizeof(_Bool));
     8        *q = b;
     9        return q;
     10}
     11
     12char* new_char( char c ) {
     13        char* q = malloc(sizeof(char));
     14        *q = c;
     15        return q;
     16}
     17
     18int* new_int( int i ) {
    619        int* q = malloc(sizeof(int));
    7         *q = *(int*)p;
     20        *q = i;
    821        return q;
     22}
     23
     24void* copy_bool( const void* p ) { return new_bool( *(const _Bool*)p ); }
     25
     26void* copy_char( const void* p ) { return new_char( *(const char*)p ); }
     27
     28void* copy_int( const void* p ) { return new_int( *(const int*)p ); }
     29
     30void* copy_pair_bool_char( const void* p ) { return copy_pair( p, copy_bool, copy_char ); }
     31
     32void free_pair_bool_char( void* p ) { free_pair( p, free, free ); }
     33
     34int cmp_bool( const void* a, const void* b ) {
     35        return *(const _Bool*)a == *(const _Bool*)b ? 0 : *(const _Bool*)a < *(const _Bool*)b ? -1 : 1;
     36}
     37
     38int cmp_char( const void* a, const void* b ) {
     39        return *(const char*)a == *(const char*)b ? 0 : *(const char*)a < *(const char*)b ? -1 : 1;
    940}
    1041
     
    1445        struct stack s = new_stack();
    1546        REPEAT_TIMED( "push_int",
    16                 int* x = malloc(sizeof(int));
    17                 *x = rand();
    18                 push_stack(&s, x);
     47                push_stack(&s, new_int( rand() ));
    1948        )
    2049
     
    2554
    2655        TIMED( "clear_int",
    27                 clear_stack(&s);
     56                clear_stack(&s, free);
    2857        )
    2958
    30         int sum;
     59        int max = 0;
    3160        REPEAT_TIMED( "pop_int",
    3261                int* x = pop_stack(&t);
    33                 sum += *x;
     62                if ( *x > max ) { max = *x; }
    3463                free(x);
    3564        )
     65
     66        struct stack s2 = new_stack();
     67        REPEAT_TIMED( "push_bool_char",
     68                push_stack(&s2, new_pair( new_bool( rand() & 0x1 ), new_char( rand() & 0x7F ) ));
     69        )
     70
     71        struct stack t2;
     72        TIMED( "copy_bool_char",
     73                copy_stack(&t2, &s2, copy_pair_bool_char);
     74        )
     75
     76        TIMED( "clear_bool_char",
     77                clear_stack(&s2, free_pair_bool_char);
     78        )
     79
     80        struct pair* max2 = new_pair( new_bool(0), new_char('\0') );
     81        REPEAT_TIMED( "pop_bool_char",
     82                struct pair* x = pop_stack(&t2);
     83                if ( cmp_pair( x, max2, cmp_bool, cmp_char ) > 0 ) {
     84                        free_pair_bool_char( max2 );
     85                        max2 = x;
     86                } else {
     87                        free_pair_bool_char( x );
     88                }
     89        )
     90        free_pair_bool_char( max2 );
    3691}
Note: See TracChangeset for help on using the changeset viewer.