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