Home | History | Annotate | Download | only in perf
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #define NLIVE 1000000
      5 
      6 #define NITERS (3*1000*1000)
      7 
      8 char* arr[NLIVE];
      9 
     10 int main ( int argc, char* argv[] )
     11 {
     12    int i, j, nbytes = 0;
     13    int pdb = 0;
     14    int jpdb;
     15 
     16    if (argc > 1) {
     17       pdb = atoi(argv[1]);
     18    }
     19 
     20    printf("initialising\n");
     21    for (i = 0; i < NLIVE; i++)
     22       arr[i] = NULL;
     23 
     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);
     36          }
     37       }
     38 
     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;
     44    }
     45 
     46    for (i = 0; i < NLIVE; i++)
     47       if (arr[i])
     48          free(arr[i]);
     49 
     50    printf("done\n");
     51    return 0;
     52 }
     53