forked from thatguystone/approxidate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.c
42 lines (31 loc) · 917 Bytes
/
benchmark.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define _XOPEN_SOURCE
#define _GNU_SOURCE 500
#include <stdio.h>
#include <time.h>
#include "approxidate.h"
#define ROUNDS 1000000
int main() {
long usec;
struct timeval start, end;
gettimeofday(&start, NULL);
for (int i = 0; i < ROUNDS; i++) {
struct timeval t;
approxidate("10/Mar/2013:00:00:02.003 -0500", &t);
}
gettimeofday(&end, NULL);
usec = end.tv_usec - start.tv_usec;
double approxidate_time = usec/((double)(1000*1000));
approxidate_time += end.tv_sec - start.tv_sec;
gettimeofday(&start, NULL);
for (int i = 0; i < ROUNDS; i++) {
struct tm m;
strptime("10/Mar/2013:00:00:02", "%d/%b/%Y:%T", &m);
}
gettimeofday(&end, NULL);
usec = end.tv_usec - start.tv_usec;
double strptime_time = usec/((double)(1000*1000));
strptime_time += end.tv_sec - start.tv_sec;
printf("approxidate time: %lf\n", approxidate_time);
printf("strptime time: %lf\n", strptime_time);
return 0;
}