bench.c (703B)
1 #include <u.h> 2 #include <libc.h> 3 4 #define BSize (1920 * 1080) 5 6 u64int *buf; 7 8 vlong 9 bench1(void (func)(void)) 10 { 11 static vlong start, end; 12 start = nsec(); 13 func(); 14 end = nsec(); 15 return end - start; 16 } 17 18 void 19 init(void) 20 { 21 buf = mallocz(sizeof(u64int) * BSize, 1); 22 } 23 24 void 25 fill(void) 26 { 27 static i; 28 for (i = 0; i < BSize; i++) { 29 static x, y, z; 30 x = i & 0xff; 31 y = i >> 8 & 0xff; 32 z = i >> 16 & 0xff; 33 buf[i] = x + y + z; 34 } 35 } 36 37 void 38 main(void) 39 { 40 static vlong sum; 41 static int i; 42 sum = bench1(init); 43 print("mallocz %lld ns\n", sum); 44 sum = bench1(fill); 45 print("fill1 %lld ns\n", sum); 46 for (sum = 0, i = 0; i < 100; i++) sum += bench1(fill); 47 print("fill100 %lld, %lld ns\n", sum, sum / 100); 48 49 }