Fix some printf()s.
[dragonfly.git] / test / sysperf / memzero.c
CommitLineData
ab4bc20f
MD
1/*
2 * memzero.c
ab4bc20f
MD
3 */
4
5#include "blib.h"
6
7int glob[16384];
8
9void test_using(const char *ctl, char *buf, int bytes, void (*zerof)(void *d, size_t bytes));
10
11extern void dozero1(void *d, size_t bytes);
12extern void dozero2(void *d, size_t bytes);
13extern void dozero3(void *d, size_t bytes);
14extern void dozero4(void *d, size_t bytes);
15extern void dozero5(void *d, size_t bytes);
16extern void dozero6(void *d, size_t bytes);
17extern void dozero7(void *d, size_t bytes);
18extern void fpcleanup(void);
19
20int
21main(int ac, char **av)
22{
23 int bytes;
24 char *ptr;
25 char *buf;
26
27 if (ac == 1) {
28 fprintf(stderr, "%s bytes\n", av[0]);
29 exit(1);
30 }
31
32 bytes = strtol(av[1], &ptr, 0);
33 switch(*ptr) {
34 case 'k':
35 case 'K':
36 bytes *= 1024;
37 break;
38 case 'm':
39 case 'M':
40 bytes *= 1024 * 1024;
41 break;
42 case 'g':
43 case 'G':
44 bytes *= 1024 * 1024 * 1024;
45 break;
46 case 0:
47 break;
48 default:
517258aa 49 fprintf(stderr, "suffix '%s' not understood\n", ptr);
ab4bc20f
MD
50 exit(1);
51 }
52 if (bytes <= 0 && (bytes & 127)) {
53 fprintf(stderr, "# of bytes must be a multiple of 128\n");
54 exit(1);
55 }
56
57 buf = mmap(NULL, bytes * 2, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0);
58 if (buf == MAP_FAILED) {
59 perror("mmap/buffer");
60 exit(1);
61 }
62 bzero(buf, bytes * 2);
63
64 test_using("bzero", buf, bytes, (void *)bzero);
7141674d 65#if 0
ab4bc20f
MD
66 test_using("dozero1", buf, bytes, dozero1);
67 test_using("dozero2", buf, bytes, dozero2);
68 test_using("dozero3", buf, bytes, dozero3);
69 test_using("dozero4", buf, bytes, dozero4);
70 test_using("dozero5", buf, bytes, dozero5);
71 test_using("dozero6", buf, bytes, dozero6);
72 test_using("dozero7", buf, bytes, dozero7);
7141674d 73#endif
ab4bc20f
MD
74 return(0);
75}
76
77void
78test_using(const char *ctl, char *buf, int bytes, void (*zerof)(void *d, size_t bytes))
79{
80 int i;
81 int loops;
82 long long us;
83
84 start_timing();
85 for (i = 0; (i & 31) || stop_timing(0, NULL) == 0; ++i) {
86 zerof(buf, bytes);
87 }
88
89 loops = i * 2;
90 start_timing();
91 for (i = loops - 1; i >= 0; --i) {
92 zerof(buf, bytes);
93 }
7141674d 94#if 0
ab4bc20f 95 fpcleanup();
7141674d 96#endif
ab4bc20f
MD
97 stop_timing(loops, ctl);
98 us = get_timing();
99 printf("%s %d %5.2f MBytes/sec\n", ctl, bytes,
100 (double)loops * (double)bytes / (double)us);
101}