2 * from ftp://ftp.netbsd.org/pub/NetBSD/misc/gmcgarry/bench/memspeed.c
6 * gcc -O3 -fomit-frame-pointer memspeed.c -o memspeed
12 #include <sys/times.h>
14 #include <sys/types.h>
19 #define TESTSIZE (8*MB)
20 #define LOOPSIZE (256*MB)
22 int main(int argc
, char *argv
[])
25 u_long size
, passes
, d
, i
, j
;
32 mb
= atol(argv
[1])*MB
;
37 fprintf(stderr
, "Usage: %s megabytes\n", argv
[0]);
44 fprintf(stderr
, "*** MEMORY WRITE PERFORMANCE (%d MB LOOP) ***\n",
46 for (size
= 64; size
<= mb
; size
<<= 1) {
47 passes
= LOOPSIZE
/size
;
48 fprintf(stderr
, "size = %9ld bytes: ", size
);
50 start
= tms
.tms_utime
;
51 for (i
= 0; i
< passes
; i
++)
52 for (j
= 0; j
< size
/sizeof(u_long
); j
+= 16) {
53 mem
[j
] = 0; mem
[j
+1] = 0; mem
[j
+2] = 0; mem
[j
+3] = 0;
54 mem
[j
+4] = 0; mem
[j
+5] = 0; mem
[j
+6] = 0; mem
[j
+7] = 0;
55 mem
[j
+8] = 0; mem
[j
+9] = 0; mem
[j
+10] = 0; mem
[j
+11] = 0;
56 mem
[j
+12] = 0; mem
[j
+13] = 0; mem
[j
+14] = 0; mem
[j
+15] = 0;
60 fprintf(stderr
, "%5.3f MB/s\n",
61 (double)(LOOPSIZE
/MB
)/(double)(stop
-start
)*(double)CLK_TCK
);
63 fprintf(stderr
, "*** MEMORY READ PERFORMANCE (%d MB LOOP) ***\n",
65 for (size
= 64; size
<= mb
; size
<<= 1) {
66 passes
= LOOPSIZE
/size
;
67 fprintf(stderr
, "size = %9ld bytes: ", size
);
69 start
= tms
.tms_utime
;
70 for (i
= 0; i
< passes
; i
++)
71 for (j
= 0; j
< size
/sizeof(u_long
); j
+= 16) {
72 d
= mem
[j
]; d
= mem
[j
+1]; d
= mem
[j
+2]; d
= mem
[j
+3];
73 d
= mem
[j
+4]; d
= mem
[j
+5]; d
= mem
[j
+6]; d
= mem
[j
+7];
74 d
= mem
[j
+8]; d
= mem
[j
+9]; d
= mem
[j
+10]; d
= mem
[j
+11];
75 d
= mem
[j
+12]; d
= mem
[j
+13]; d
= mem
[j
+14]; d
= mem
[j
+15];
79 fprintf(stderr
, "%5.3f MB/s\n",
80 (double)(LOOPSIZE
/MB
)/(double)(stop
-start
)*(double)CLK_TCK
);