drd: Improve barrier support
[valgrind.git] / perf / heap.c
blob8b38bec2227d518fb98e6e97cf79825281669829
1 #include <stdio.h>
2 #include <stdlib.h>
4 #define NLIVE 1000000
6 #define NITERS (3*1000*1000)
8 char* arr[NLIVE];
10 int main ( int argc, char* argv[] )
12 int i, j, nbytes = 0;
13 int pdb = 0;
14 int jpdb;
16 if (argc > 1) {
17 pdb = atoi(argv[1]);
20 printf("initialising\n");
21 for (i = 0; i < NLIVE; i++)
22 arr[i] = NULL;
24 printf("running\n");
25 j = -1;
26 for (i = 0; i < NITERS; i++) {
27 j++;
28 if (j == NLIVE) j = 0;
29 if (arr[j])
30 free(arr[j]);
31 arr[j] = malloc(nbytes);
32 if (pdb > 0) {
33 // create some partially defined bytes in arr[j]
34 for (jpdb=0; jpdb<nbytes; jpdb = jpdb+pdb) {
35 arr[j][jpdb] &= (jpdb & 0xff);
39 // Cycle through the sizes 0,8,16,24,32. Zero will get rounded up to
40 // 8, so the 8B bucket will get twice as much traffic.
41 nbytes += 8;
42 if (nbytes > 32)
43 nbytes = 0;
46 for (i = 0; i < NLIVE; i++)
47 if (arr[i])
48 free(arr[i]);
50 printf("done\n");
51 return 0;