1#include <stdio.h>
2#include <sys/time.h>
3
4extern void icache_test(long count, long step);
5extern void icache_test2(long count);
6
7int main()
8{
9    printf("[bytes]\t[us]\n");
10
11    struct timeval now, tm;
12    long long t;
13    long MBs;
14    long i;
15    long step = 32;
16    for (i=0 ; step<=2048 ; i++, step+=32)
17    {
18        long value;
19        gettimeofday(&now, 0);
20        icache_test(0x800000L, step);
21        gettimeofday(&tm, 0);
22        t = (tm.tv_sec*1000000LL+tm.tv_usec) - (now.tv_sec*1000000LL+now.tv_usec);
23        printf("%6ld\t%lld\n", step*32, t);
24    }
25
26    gettimeofday(&now, 0);
27    icache_test2(0x800000L / 2048);
28    gettimeofday(&tm, 0);
29    t = (tm.tv_sec*1000000LL+tm.tv_usec) - (now.tv_sec*1000000LL+now.tv_usec);
30    MBs = (8388608LL*32*1000000) / (t * (1024*1024));
31    printf("\n%6lld us\t%ld MB/s\n", t, MBs);
32
33    return 0;
34}
35