-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.c
More file actions
101 lines (89 loc) · 2.69 KB
/
Copy pathbench.c
File metadata and controls
101 lines (89 loc) · 2.69 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define algn __attribute__ ((aligned (8)))
#define NITER 40000000
#define MULTIPLIER 1
#define PIECE "Hello world, Itanium is not dead and will not be for a very long time."
#define PIECEA PIECE "a"
#define PIECEB PIECE "b"
#define LONG_A PIECEA PIECEA PIECEA
#define LONG_B PIECEA PIECEA PIECEB
#define S16B_A "HELLOWOA"
#define S16B_B "HELLOWOB"
#ifdef USE_STRNCMP
#define FN "strncmp"
#define CMPFN(a, b) strncmp(a, b, sizeof(b))
#else
#define FN "strcmp"
#define CMPFN(a, b) strcmp(a, b)
#endif
double iter_per_msec(struct timespec *a, struct timespec *b, int multiplier)
{
double time = (b->tv_sec * 1000.0 + b->tv_nsec / 1000000.0) - (a->tv_sec * 1000.0 + a->tv_nsec / 1000000.0);
return (NITER * multiplier) / time;
}
#define PAIR(name, left, right) \
char name##_align_a[] algn = left;\
char name##_align_b[] algn = right;\
char name##_noalign_a_[] algn = " " left;\
char name##_noalign_b_[] algn = " " right;\
char *name##_noalign_a = name##_noalign_a_ + 1;\
char *name##_noalign_b = name##_noalign_b_ + 1;
PAIR(long_equal, LONG_A, LONG_A)
PAIR(long_nonequal, LONG_A, LONG_B)
PAIR(s16b_equal, S16B_A, S16B_A)
PAIR(s16b_nonequal, S16B_A, S16B_B)
PAIR(one_char_eq, "a", "a")
PAIR(one_char_neq, "a" PIECE, "b" PIECE)
PAIR(two_char_neq, "aa" PIECE, "ab" PIECE)
PAIR(three_char_neq, "aaa" PIECE, "aab" PIECE)
PAIR(four_char_neq, "aaaa" PIECE, "aaab" PIECE)
#define CASE(name, expected_result) do {\
x = CMPFN(name##_a, name##_b);\
if (x > 0)\
x = 1;\
else if (x < 0)\
x = -1;\
if (x != expected_result) {\
printf("ERROR! Mismatch on " #name ": expected %d, got %d!\n", expected_result, x);\
exit(1);\
}\
clock_gettime(CLOCK_MONOTONIC, &before);\
for (i = 0; i < NITER * MULTIPLIER; i++) {\
x = CMPFN(name##_a, name##_b);\
}\
clock_gettime(CLOCK_MONOTONIC, &after);\
printf(#name ":\t%f iter/msec\n", iter_per_msec(&before, &after, MULTIPLIER));\
} while (0);
#ifdef USE_STRNCMP
#define CASES(name, expected_result) do {\
CASE(name##_align, expected_result)\
} while (0);
#else
#define CASES(name, expected_result) do {\
CASE(name##_align, expected_result)\
CASE(name##_noalign, expected_result)\
} while (0);
#endif
int main()
{
unsigned long i;
volatile int x __attribute__ ((unused));
struct timespec before, after;
printf("Versatile libc " FN "() benchmark for 64-bit machines\n");
printf("By: EPIC Linux project, http://www.epic-linux.org\n");
printf("\n");
CASES(long_equal, 0)
CASES(long_nonequal, -1)
#undef MULTIPLIER
#define MULTIPLIER 10
CASES(s16b_equal, 0)
CASES(s16b_nonequal, -1)
CASES(one_char_eq, 0)
CASES(one_char_neq, -1)
CASES(two_char_neq, -1)
CASES(three_char_neq, -1)
CASES(four_char_neq, -1)
}