-
Notifications
You must be signed in to change notification settings - Fork 2
/
time_xatoull.c
70 lines (61 loc) · 2.01 KB
/
time_xatoull.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "tdiff.h"
extern const char* xatoull(const char* string, unsigned long long* value);
extern const char* c_xatoull(const char* string, unsigned long long* value);
extern void noop();
int main(int argc, char* argv[]) {
struct timespec clock1, clock2;
unsigned int count;
puts("string strtoull():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(strtoll("1234567890", NULL, 0));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("string xatoull():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
unsigned long long value;
xatoull("1234567890", &value);
}
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("string c_xatoull():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
unsigned long long value;
noop(c_xatoull("1234567890", &value));
noop(value);
}
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
if (argc < 2)
return EXIT_SUCCESS;
puts("arg strtoll():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(strtoll(argv[1], NULL, 0));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("arg xatoull():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
unsigned long long value;
xatoull(argv[1], &value);
}
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("arg c_xatoull():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
unsigned long long value;
noop(c_xatoull(argv[1], &value));
noop(value);
}
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
return EXIT_SUCCESS;
}