diff options
Diffstat (limited to 'nacl/cpucycles/test.c')
-rw-r--r-- | nacl/cpucycles/test.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/nacl/cpucycles/test.c b/nacl/cpucycles/test.c new file mode 100644 index 00000000..bc43d719 --- /dev/null +++ b/nacl/cpucycles/test.c | |||
@@ -0,0 +1,77 @@ | |||
1 | #include <time.h> | ||
2 | #include <stdio.h> | ||
3 | #include <unistd.h> | ||
4 | #include <sys/time.h> | ||
5 | #include "cpucycles-impl.h" | ||
6 | |||
7 | static long long tod(void) | ||
8 | { | ||
9 | struct timeval t; | ||
10 | gettimeofday(&t,(struct timezone *) 0); | ||
11 | return t.tv_sec * (long long) 1000000 + t.tv_usec; | ||
12 | } | ||
13 | |||
14 | long long todstart; | ||
15 | long long todend; | ||
16 | long long cpustart; | ||
17 | long long cpuend; | ||
18 | |||
19 | long long cyclespersecond; | ||
20 | long long cyclespertod; | ||
21 | |||
22 | long long t[1001]; | ||
23 | |||
24 | int main() | ||
25 | { | ||
26 | int j; | ||
27 | int i; | ||
28 | |||
29 | if (!cpucycles()) { | ||
30 | fprintf(stderr,"cpucycles() = %lld\n",cpucycles()); | ||
31 | return 100; | ||
32 | } | ||
33 | for (i = 0;i <= 1000;++i) t[i] = cpucycles(); | ||
34 | for (i = 0;i < 1000;++i) if (t[i] > t[i + 1]) { | ||
35 | fprintf(stderr,"t[%d] = %lld\n",i,t[i]); | ||
36 | fprintf(stderr,"t[%d] = %lld\n",i + 1,t[i + 1]); | ||
37 | fprintf(stderr,"cpucycles_persecond() = %lld\n",cpucycles_persecond()); | ||
38 | return 100; | ||
39 | } | ||
40 | if (t[0] == t[1000]) { | ||
41 | fprintf(stderr,"t[%d] = %lld\n",0,t[0]); | ||
42 | fprintf(stderr,"t[%d] = %lld\n",1000,t[1000]); | ||
43 | fprintf(stderr,"cpucycles_persecond() = %lld\n",cpucycles_persecond()); | ||
44 | return 100; | ||
45 | } | ||
46 | |||
47 | cyclespersecond = cpucycles_persecond(); | ||
48 | |||
49 | if (cyclespersecond <= 0) { | ||
50 | fprintf(stderr,"cpucycles_persecond() = %lld\n",cyclespersecond); | ||
51 | return 100; | ||
52 | } | ||
53 | |||
54 | todstart = tod(); | ||
55 | cpustart = cpucycles(); | ||
56 | for (j = 0;j < 1000;++j) for (i = 0;i <= 1000;++i) t[i] = t[i] + i + j; | ||
57 | todend = tod(); | ||
58 | cpuend = cpucycles(); | ||
59 | |||
60 | todend -= todstart; | ||
61 | cpuend -= cpustart; | ||
62 | |||
63 | cyclespertod = (long long) (((double) cpuend) * 1000000.0 / (double) todend); | ||
64 | |||
65 | if (cyclespertod > 10 * cyclespersecond) { | ||
66 | fprintf(stderr,"cyclespertod = %lld, cyclespersecond = %lld\n",cyclespertod,cyclespersecond); | ||
67 | return 100; | ||
68 | } | ||
69 | |||
70 | for (i = 0;i <= 1000;++i) t[i] = cpucycles(); | ||
71 | printf("%s",cpucycles_implementation); | ||
72 | printf(" %lld",cyclespersecond); | ||
73 | printf(" %lld",cyclespertod); | ||
74 | for (i = 0;i < 64;++i) printf(" %lld",t[i + 1] - t[i]); | ||
75 | printf("\n"); | ||
76 | return 0; | ||
77 | } | ||