12
gettimeofday(&tv, NULL);
14
return tv.tv_sec + tv.tv_usec * 1e-6;
17
static int get_arg(int argc, char **argv, int idx, int fallback)
21
return atoi(argv[idx]);
29
static void empty(volatile char *against)
31
/* We know that there's a 16 k cache with 64 byte lines giving
32
a total of 256 lines. Read randomly from 256*5 places should
34
int offset = (1024 - 256)*1024;
36
for (int i = offset; i < offset + 16*1024*3; i += 64)
42
static void __attribute__((noinline)) xmemcpy(char *dest, char *src, size_t n)
47
static void __attribute__((noinline)) xstrcpy(char *dest, char *src)
52
static void __attribute__((noinline)) xmemset(void *dest, int c, size_t n)
57
int main(int argc, char **argv)
59
char *src = calloc(1024, 1024);
60
char *dest = calloc(1024, 1024);
64
for (int i = 0; i < 16*1024; i++)
66
src[i] = (char)random() | 1;
69
int count = get_arg(argc, argv, 1, 31);
70
int loops = get_arg(argc, argv, 2, 10000000);
71
int flush = get_arg(argc, argv, 3, 0);
77
for (int i = 0; i < loops; i++)
79
#if defined(WITH_MEMCPY)
80
xmemcpy(dest, src, count);
81
#elif defined(WITH_STRCPY)
83
#elif defined(WITH_MEMSET)
84
xmemset(src, 0, count);
96
double elapsed = end - start;
98
printf("%.3f for %u loops of %u bytes. %.3f MB/s\n", elapsed, loops, count, (double)loops*count/elapsed/(1024*1024));