1 // SPDX-License-Identifier: GPL-2.0
9 #define ITERATIONS 1000
10 #define ITERATIONS_BENCH 100000
12 int test_strlen(const void *s
);
14 /* test all offsets and lengths */
15 static void test_one(char *s
)
19 for (offset
= 0; offset
< SIZE
; offset
++) {
23 y
= strlen(s
+ offset
);
24 x
= test_strlen(s
+ offset
);
27 printf("strlen() returned %d, should have returned %d (%p offset %ld)\n", x
, y
, s
, offset
);
29 for (i
= offset
; i
< SIZE
; i
++)
30 printf("%02x ", s
[i
]);
36 static void bench_test(char *s
)
38 struct timespec ts_start
, ts_end
;
41 clock_gettime(CLOCK_MONOTONIC
, &ts_start
);
43 for (i
= 0; i
< ITERATIONS_BENCH
; i
++)
46 clock_gettime(CLOCK_MONOTONIC
, &ts_end
);
48 printf("len %3.3d : time = %.6f\n", test_strlen(s
), ts_end
.tv_sec
- ts_start
.tv_sec
+ (ts_end
.tv_nsec
- ts_start
.tv_nsec
) / 1e9
);
51 static int testcase(void)
56 s
= memalign(128, SIZE
);
65 for (i
= 0; i
< SIZE
; i
++) {
75 for (i
= 0; i
< ITERATIONS
; i
++) {
78 for (j
= 0; j
< SIZE
; j
++) {
86 for (j
= 0; j
< sizeof(long); j
++) {
92 for (i
= 0; i
< SIZE
; i
++) {
126 return test_harness(testcase
, "strlen");