]> git.sesse.net Git - fjl/blob - benchmark.c
Add an x86 optimized version of extend().
[fjl] / benchmark.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4
5 static struct timespec start_time;
6
7 void start_benchmark_timer()
8 {
9         if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time) == -1) {
10                 perror("clock_gettime()");
11                 exit(1);
12         }
13 }
14
15 static double timediff(const struct timespec* a, const struct timespec* b)
16 {
17         return (double)(b->tv_sec - a->tv_sec) +
18                 (double)(b->tv_nsec - a->tv_nsec) * 1e-9;
19 }
20
21 double stop_benchmark_timer()
22 {
23         struct timespec now;
24         if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now) == -1) {
25                 perror("clock_gettime()");
26                 exit(1);
27         }
28
29         return timediff(&start_time, &now);
30 }