1 /* Measure strlen functions.
2 Copyright (C) 2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #define TEST_NAME "strnlen"
21 #include "bench-string.h"
23 typedef size_t (*proto_t
) (const char *, size_t);
24 size_t simple_strnlen (const char *, size_t);
26 IMPL (simple_strnlen
, 0)
30 simple_strnlen (const char *s
, size_t maxlen
)
34 for (i
= 0; i
< maxlen
&& s
[i
]; ++i
);
39 do_one_test (impl_t
*impl
, const char *s
, size_t maxlen
, size_t exp_len
)
41 size_t len
= CALL (impl
, s
, maxlen
);
44 error (0, 0, "Wrong result in function %s %zd %zd", impl
->name
,
52 hp_timing_t start
__attribute ((unused
));
53 hp_timing_t stop
__attribute ((unused
));
54 hp_timing_t best_time
= ~ (hp_timing_t
) 0;
57 for (i
= 0; i
< 32; ++i
)
59 HP_TIMING_NOW (start
);
60 CALL (impl
, s
, maxlen
);
62 HP_TIMING_BEST (best_time
, start
, stop
);
65 printf ("\t%zd", (size_t) best_time
);
70 do_test (size_t align
, size_t len
, size_t maxlen
, int max_char
)
75 if (align
+ len
>= page_size
)
78 for (i
= 0; i
< len
; ++i
)
79 buf1
[align
+ i
] = 1 + 7 * i
% max_char
;
80 buf1
[align
+ len
] = 0;
83 printf ("Length %4zd, alignment %2zd:", len
, align
);
85 FOR_EACH_IMPL (impl
, 0)
86 do_one_test (impl
, (char *) (buf1
+ align
), maxlen
, MIN (len
, maxlen
));
100 FOR_EACH_IMPL (impl
, 0)
101 printf ("\t%s", impl
->name
);
104 for (i
= 1; i
< 8; ++i
)
106 do_test (0, i
, i
- 1, 127);
107 do_test (0, i
, i
, 127);
108 do_test (0, i
, i
+ 1, 127);
111 for (i
= 1; i
< 8; ++i
)
113 do_test (i
, i
, i
- 1, 127);
114 do_test (i
, i
, i
, 127);
115 do_test (i
, i
, i
+ 1, 127);
118 for (i
= 2; i
<= 10; ++i
)
120 do_test (0, 1 << i
, 5000, 127);
121 do_test (1, 1 << i
, 5000, 127);
124 for (i
= 1; i
< 8; ++i
)
125 do_test (0, i
, 5000, 255);
127 for (i
= 1; i
< 8; ++i
)
128 do_test (i
, i
, 5000, 255);
130 for (i
= 2; i
<= 10; ++i
)
132 do_test (0, 1 << i
, 5000, 255);
133 do_test (1, 1 << i
, 5000, 255);
139 #include "../test-skeleton.c"