1 /* Measure STRLEN functions.
2 Copyright (C) 2013-2015 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/>. */
21 # define TEST_NAME "strlen"
23 # define TEST_NAME "wcslen"
25 #include "bench-string.h"
28 # define STRLEN strlen
30 # define MAX_CHAR CHAR_MAX
33 # define STRLEN wcslen
35 # define MAX_CHAR WCHAR_MAX
38 typedef size_t (*proto_t
) (const CHAR
*);
41 simple_STRLEN (const CHAR
*s
)
51 builtin_strlen (const CHAR
*p
)
53 return __builtin_strlen (p
);
55 IMPL (builtin_strlen
, 0)
58 IMPL (simple_STRLEN
, 0)
63 do_one_test (impl_t
*impl
, const CHAR
*s
, size_t exp_len
)
65 size_t len
= CALL (impl
, s
), i
, iters
= INNER_LOOP_ITERS
;
66 timing_t start
, stop
, cur
;
70 error (0, 0, "Wrong result in function %s %zd %zd", impl
->name
,
77 for (i
= 0; i
< iters
; ++i
)
83 TIMING_DIFF (cur
, start
, stop
);
85 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
89 do_test (size_t align
, size_t len
)
94 if (align
+ sizeof(CHAR
) * len
>= page_size
)
97 CHAR
*buf
= (CHAR
*) (buf1
);
99 for (i
= 0; i
< len
; ++i
)
100 buf
[align
+ i
] = 1 + 11111 * i
% MAX_CHAR
;
101 buf
[align
+ len
] = 0;
103 printf ("Length %4zd, alignment %2zd:", len
, align
);
105 FOR_EACH_IMPL (impl
, 0)
106 do_one_test (impl
, (CHAR
*) (buf
+ align
), len
);
119 FOR_EACH_IMPL (impl
, 0)
120 printf ("\t%s", impl
->name
);
123 /* Checking with only 4 * N alignments for wcslen, other alignments are wrong for wchar_t type arrays*/
125 for (i
= 1; i
< 8; ++i
)
127 do_test (sizeof(CHAR
) * i
, i
);
131 for (i
= 2; i
<= 12; ++i
)
134 do_test (sizeof(CHAR
) * 7, 1 << i
);
135 do_test (sizeof(CHAR
) * i
, 1 << i
);
136 do_test (sizeof(CHAR
) * i
, (size_t)((1 << i
) / 1.5));
142 #include "../test-skeleton.c"