vfs: check userland buffers before reading them.
[haiku.git] / src / tests / system / benchmarks / memspeed.c
blob66643a131295a0c2a9d0c44c7da25a98b79958f5
1 /*
2 * from ftp://ftp.netbsd.org/pub/NetBSD/misc/gmcgarry/bench/memspeed.c
4 * Compilation:
6 * gcc -O3 -fomit-frame-pointer memspeed.c -o memspeed
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <sys/times.h>
13 #include <time.h>
14 #include <sys/types.h>
16 #define KB (1024)
17 #define MB (KB*KB)
19 #define TESTSIZE (8*MB)
20 #define LOOPSIZE (256*MB)
22 int main(int argc, char *argv[])
24 u_long mb = TESTSIZE;
25 u_long size, passes, d, i, j;
26 volatile u_long *mem;
27 struct tms tms;
28 time_t start, stop;
30 switch (argc) {
31 case 2:
32 mb = atol(argv[1])*MB;
33 case 1:
34 break;
36 default:
37 fprintf(stderr, "Usage: %s megabytes\n", argv[0]);
38 exit(1);
39 break;
42 mem = malloc(mb);
44 fprintf(stderr, "*** MEMORY WRITE PERFORMANCE (%d MB LOOP) ***\n",
45 LOOPSIZE/MB);
46 for (size = 64; size <= mb; size <<= 1) {
47 passes = LOOPSIZE/size;
48 fprintf(stderr, "size = %9ld bytes: ", size);
49 times(&tms);
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;
58 times(&tms);
59 stop = tms.tms_utime;
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",
64 LOOPSIZE/MB);
65 for (size = 64; size <= mb; size <<= 1) {
66 passes = LOOPSIZE/size;
67 fprintf(stderr, "size = %9ld bytes: ", size);
68 times(&tms);
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];
77 times(&tms);
78 stop = tms.tms_utime;
79 fprintf(stderr, "%5.3f MB/s\n",
80 (double)(LOOPSIZE/MB)/(double)(stop-start)*(double)CLK_TCK);
82 exit(0);