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