-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtime_xatoll.c
84 lines (73 loc) · 2.41 KB
/
time_xatoll.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "tdiff.h"
extern const char* xatoll(const char* string, long long* value);
extern const char* c_xatoll(const char* string, long long* value);
extern void noop();
int main(int argc, char* argv[]) {
struct timespec clock1, clock2;
unsigned int count;
puts("string atoll():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(atoll("1234567890"));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
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 xatoll():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
long long value;
xatoll("1234567890", &value);
}
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("string c_xatoll():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
long long value;
noop(c_xatoll("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 atoll():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(atoll(argv[1]));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
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 xatoll():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
long long value;
xatoll(argv[1], &value);
}
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("arg c_xatoll():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count) {
long long value;
noop(c_xatoll(argv[1], &value));
noop(value);
}
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
return EXIT_SUCCESS;
}