5 #define lsize sizeof(unsigned long)
7 long usec_diff(const struct timeval *a, const struct timeval *b)
10 usec_a = a->tv_sec * 1000000 + a->tv_usec;
11 usec_b = b->tv_sec * 1000000 + b->tv_usec;
12 return usec_b - usec_a;
15 int main(int argc, char *argv[])
17 int iterations, j, k, count, size;
18 unsigned long *buf, i, tmp = 0;
19 struct timeval start, end;
22 iterations = atoi(argv[1]);
27 count = atoi(argv[2]) * 1024;
31 printf("Doing %d runs with buffer size goin up to %dk\n",
32 iterations, 1 << (iterations - 10));
33 printf("Running each round %d times\n", count);
34 printf("Size of unsigned long is %lu bits\n", lsize * 8);
48 for (; j < iterations + 1; j++) {
49 size = (1 << j) / lsize;
50 buf = malloc(size * lsize);
53 printf("Malloc failed\n");
58 for (i = 0; i < size; i++)
61 printf("%luk\t", size * lsize / 1024);
66 gettimeofday(&start, 0);
67 for (k = 0; k < count; k++) {
69 for (i = 0; i < size; i++)
73 gettimeofday(&end, 0);
75 printf("% 9.2f MB/s ", (double)(size * lsize) *
76 (1000000 / (1024.0 * 1024.0)) * count /
77 (double) usec_diff(&start, &end));
83 gettimeofday(&start, 0);
84 for (k = 0; k < count; k++)
85 for (i = 0; i < size; i++)
87 gettimeofday(&end, 0);
89 printf("% 9.2f MB/s ", (double)(size * lsize) *
90 (1000000 / (1024.0 * 1024.0)) * count /
91 (double) usec_diff(&start, &end));