drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / callgrind / tests / simwork.c
blob02197fc415567d2497c1480f7a8d685be53ac60c
1 // Some work exercising the cache simulator
2 // with a simple call graph
4 #include "../callgrind.h"
6 #include <stdio.h>
7 #include <stdlib.h>
9 #define SIZE 100000
11 double *a, *b, *c;
13 void init()
15 int i;
16 for(i = 0; i< SIZE; i++) a[i] = b[i] = 1.0;
19 void do_add()
21 int i;
22 for(i = 0; i< SIZE; i++) {
23 a[i] += 1.0;
24 c[i] = a[i] + b[i];
28 double do_sum()
30 int i;
31 double sum=0.0;
33 do_add();
34 for(i = 0; i< SIZE; i++) sum += c[i];
36 return sum;
39 double do_some_work(int iter)
41 double sum=0.0;
43 if (iter > 0) sum += do_some_work(iter-1);
44 do_add();
45 sum += do_sum();
47 return sum;
50 int main(void)
52 double res;
54 a = (double*) malloc(SIZE * sizeof(double));
55 b = (double*) malloc(SIZE * sizeof(double));
56 c = (double*) malloc(SIZE * sizeof(double));
58 CALLGRIND_ZERO_STATS;
59 init();
60 res = do_some_work(1);
61 CALLGRIND_DUMP_STATS;
63 printf("Sum: %.0f\n", res);
64 return RUNNING_ON_VALGRIND;