source: doc/generic_types/evaluation/c-bench.c @ 122aecd

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 122aecd was 122aecd, checked in by Aaron Moss <a3moss@…>, 5 years ago

Expand benchmarks

  • Property mode set to 100644
File size: 542 bytes
RevLine 
[309be81]1#include <stdlib.h>
2#include "bench.h"
3#include "c-stack.h"
4
[122aecd]5void* copy_int( void* p ) {
6        int* q = malloc(sizeof(int));
7        *q = *(int*)p;
8        return q;
9}
10
[309be81]11int main(int argc, char** argv) {
12        srand(20171025);
13
14        struct stack s = new_stack();
15        REPEAT_TIMED( "push_int",
16                int* x = malloc(sizeof(int));
17                *x = rand();
18                push_stack(&s, x);
19        )
20
[122aecd]21        struct stack t;
22        TIMED( "copy_int",
23                copy_stack(&t, &s, copy_int);
24        )
25
26        TIMED( "clear_int",
27                clear_stack(&s);
28        )
29
30        int sum;
31        REPEAT_TIMED( "pop_int", 
32                int* x = pop_stack(&t);
33                sum += *x;
34                free(x);
35        )
[309be81]36}
Note: See TracBrowser for help on using the repository browser.