1 /* 2 * BLIB.C 3 * 4 * Simple benchmarking library 5 * 6 * $DragonFly: src/test/sysperf/blib.c,v 1.5 2006/04/22 22:32:52 dillon Exp $ 7 */ 8 9 #include <sys/types.h> 10 #include <sys/time.h> 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <stdarg.h> 14 15 static struct timeval tv1; 16 static struct timeval tv2; 17 18 void 19 start_timing(void) 20 { 21 gettimeofday(&tv1, NULL); 22 } 23 24 int 25 stop_timing(long long count, const char *ctl, ...) 26 { 27 long long us; 28 va_list va; 29 30 gettimeofday(&tv2, NULL); 31 us = (tv2.tv_usec - tv1.tv_usec) + (tv2.tv_sec - tv1.tv_sec) * 1000000LL; 32 if (ctl == NULL) /* dummy call to pre-cache */ 33 return(us > 1000000); 34 35 va_start(va, ctl); 36 vprintf(ctl, va); 37 va_end(va); 38 39 printf(" %6.3fs %lld loops = %6.3fuS/loop\n", 40 (double)us / 1000000.0, 41 count, 42 (double)us / (double)count 43 ); 44 return(0); 45 } 46 47 int 48 stop_timing2(long long count, long long us, const char *ctl, ...) 49 { 50 va_list va; 51 52 va_start(va, ctl); 53 vprintf(ctl, va); 54 va_end(va); 55 56 printf(" %6.3fs %lld loops = %6.3fnS/loop\n", 57 (double)us / 1000000.0, 58 count, 59 (double)us * 1000.0 / (double)count 60 ); 61 return(0); 62 } 63 64 long long 65 get_timing(void) 66 { 67 long long us; 68 69 gettimeofday(&tv2, NULL); 70 us = (tv2.tv_usec - tv1.tv_usec) + (tv2.tv_sec - tv1.tv_sec) * 1000000LL; 71 return(us); 72 } 73 74 void 75 nop(void) 76 { 77 } 78