Merge commit 'crater/master'
[dragonfly.git] / test / sysperf / memcpy.c
blob997bc9ab0464d9bfa94245ecaa1a0a746fe4fdce
1 /*
2 * memcpy.c
4 * $DragonFly: src/test/sysperf/memcpy.c,v 1.1 2004/04/29 16:14:53 dillon Exp $
5 */
7 #include "blib.h"
9 int glob[16384];
11 void test_using(const char *ctl, char *buf, int bytes, void (*copyf)(const void *s1, void *d, size_t bytes));
13 extern void docopy1(const void *s, void *d, size_t bytes);
14 extern void docopy2(const void *s, void *d, size_t bytes);
15 extern void docopy3(const void *s, void *d, size_t bytes);
16 extern void docopy4(const void *s, void *d, size_t bytes);
17 extern void docopy5(const void *s, void *d, size_t bytes);
18 extern void docopy6(const void *s, void *d, size_t bytes);
19 extern void docopy7(const void *s, void *d, size_t bytes);
20 extern void fpcleanup(void);
22 int
23 main(int ac, char **av)
25 int bytes;
26 char *ptr;
27 char *buf;
29 if (ac == 1) {
30 fprintf(stderr, "%s bytes\n", av[0]);
31 exit(1);
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:
51 fprintf(stderr, "suffix '%s' not understood\n");
52 exit(1);
54 if (bytes <= 0 && (bytes & 127)) {
55 fprintf(stderr, "# of bytes must be a multiple of 128\n");
56 exit(1);
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);
63 bzero(buf, bytes * 2);
65 test_using("bcopy", buf, bytes, bcopy);
66 test_using("docopy1", buf, bytes, docopy1);
67 test_using("docopy2", buf, bytes, docopy2);
68 test_using("docopy3", buf, bytes, docopy3);
69 test_using("docopy4", buf, bytes, docopy4);
70 test_using("docopy5", buf, bytes, docopy5);
71 test_using("docopy6", buf, bytes, docopy6);
72 test_using("docopy7", buf, bytes, docopy7);
73 return(0);
76 void
77 test_using(const char *ctl, char *buf, int bytes, void (*copyf)(const void *s1, void *d, size_t bytes))
79 int i;
80 int loops;
81 long long us;
83 start_timing();
84 for (i = 0; (i & 31) || stop_timing(0, NULL) == 0; ++i) {
85 copyf(buf, buf + bytes, bytes);
88 loops = i * 2;
89 start_timing();
90 for (i = loops - 1; i >= 0; --i) {
91 copyf(buf, buf + bytes, bytes);
93 fpcleanup();
94 stop_timing(loops, ctl);
95 us = get_timing();
96 printf("%s %d %5.2f MBytes/sec\n", ctl, bytes,
97 (double)loops * (double)bytes / (double)us);