-
Notifications
You must be signed in to change notification settings - Fork 2
/
time_xstrchr.c
111 lines (96 loc) · 3.46 KB
/
time_xstrchr.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "tdiff.h"
extern const char* xstrchr(const char* string, char value);
extern const char* xstrchr_lods(const char* string, char value);
#ifdef __SSE2__
extern const char* xstrchr_sse2(const char* string, char value);
#endif
extern const char* c_xstrchr(const char* string, char value);
extern void noop();
int main(int argc, char* argv[]) {
struct timespec clock1, clock2;
unsigned int count;
puts("string strchr():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(strchr("1234567890", '0'));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("string strchrnul():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(strchrnul("1234567890", '0'));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("string xstrchr():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
xstrchr("1234567890", '0');
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("string xstrchr_lods():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
xstrchr_lods("1234567890", '0');
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
#ifdef __SSE2__
puts("string xstrchr_sse2():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
xstrchr_sse2("1234567890", '0');
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
#endif
puts("string c_xstrchr():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(c_xstrchr("1234567890", '0'));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
if (argc < 2)
return EXIT_SUCCESS;
puts("arg strchr():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(strchr(argv[1], '0'));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("arg strchrnul():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(strchrnul(argv[1], '0'));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("arg xstrchr():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
xstrchr(argv[1], '0');
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
puts("arg xstrchr_lods():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
xstrchr_lods(argv[1], '0');
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
#ifdef __SSE2__
puts("arg xstrchr_sse2():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
xstrchr_sse2(argv[1], '0');
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
#endif
puts("arg c_xstrchr():");
clock_gettime(CLOCK_MONOTONIC, &clock1);
for (count = 0; count < 10000000; ++count)
noop(c_xstrchr(argv[1], '0'));
clock_gettime(CLOCK_MONOTONIC, &clock2);
printf("%8lli ms\n", tdiff(clock1, clock2)/1000000);
return EXIT_SUCCESS;
}