test.c (935B)
1 #include <errno.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <time.h> 5 #include <unistd.h> 6 7 #include "benchmark.h" 8 9 /* usleep(): Sleep for the requested number of microseconds. */ 10 int musleep(long usec) { 11 struct timespec ts; 12 int res; 13 14 if (usec < 0) { 15 return -1; 16 } 17 18 ts.tv_sec = usec / 1000000; 19 ts.tv_nsec = (usec % 1000000) * 1000; 20 21 do { 22 res = nanosleep(&ts, &ts); 23 } while (res && errno == EINTR); 24 25 return res; 26 } 27 28 29 void mindex_some_bmark_method() { 30 // Intentionally empty 31 musleep(100 + (rand() % 100)); 32 } 33 34 int main() { 35 36 // Seed random 37 unsigned int seed; 38 FILE* urandom = fopen("/dev/urandom", "r"); 39 fread(&seed, sizeof(int), 1, urandom); 40 fclose(urandom); 41 srand(seed); 42 43 // Enqueue benchmarks 44 BMARK(mindex_some_bmark_method); 45 46 char percentiles[] = { 47 1 , 5, 20, 48 50, 49 80, 95, 99, 50 0 51 }; 52 53 // Run & return 54 return bmark_run(100, percentiles); 55 }