1 /* 2 * memzero.c 3 * 4 * $DragonFly: src/test/sysperf/memzero.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 (*zerof)(void *d, size_t bytes)); 12 13 extern void dozero1(void *d, size_t bytes); 14 extern void dozero2(void *d, size_t bytes); 15 extern void dozero3(void *d, size_t bytes); 16 extern void dozero4(void *d, size_t bytes); 17 extern void dozero5(void *d, size_t bytes); 18 extern void dozero6(void *d, size_t bytes); 19 extern void dozero7(void *d, size_t bytes); 20 extern void fpcleanup(void); 21 22 int 23 main(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: 51 fprintf(stderr, "suffix '%s' not understood\n"); 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 59 buf = mmap(NULL, bytes * 2, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0); 60 if (buf == MAP_FAILED) { 61 perror("mmap/buffer"); 62 exit(1); 63 } 64 bzero(buf, bytes * 2); 65 66 test_using("bzero", buf, bytes, (void *)bzero); 67 #if 0 68 test_using("dozero1", buf, bytes, dozero1); 69 test_using("dozero2", buf, bytes, dozero2); 70 test_using("dozero3", buf, bytes, dozero3); 71 test_using("dozero4", buf, bytes, dozero4); 72 test_using("dozero5", buf, bytes, dozero5); 73 test_using("dozero6", buf, bytes, dozero6); 74 test_using("dozero7", buf, bytes, dozero7); 75 #endif 76 return(0); 77 } 78 79 void 80 test_using(const char *ctl, char *buf, int bytes, void (*zerof)(void *d, size_t bytes)) 81 { 82 int i; 83 int loops; 84 long long us; 85 86 start_timing(); 87 for (i = 0; (i & 31) || stop_timing(0, NULL) == 0; ++i) { 88 zerof(buf, bytes); 89 } 90 91 loops = i * 2; 92 start_timing(); 93 for (i = loops - 1; i >= 0; --i) { 94 zerof(buf, bytes); 95 } 96 #if 0 97 fpcleanup(); 98 #endif 99 stop_timing(loops, ctl); 100 us = get_timing(); 101 printf("%s %d %5.2f MBytes/sec\n", ctl, bytes, 102 (double)loops * (double)bytes / (double)us); 103 } 104