]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-rawmemchr.c
nss_dns: Remove RES_USE_INET6 handling
[thirdparty/glibc.git] / benchtests / bench-rawmemchr.c
CommitLineData
97020474 1/* Measure memchr functions.
04277e02 2 Copyright (C) 2013-2019 Free Software Foundation, Inc.
97020474
SP
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19#include <assert.h>
16f87cfd 20#include <stdint.h>
97020474
SP
21
22#define TEST_MAIN
23#define TEST_NAME "rawmemchr"
24#include "bench-string.h"
25
26typedef char *(*proto_t) (const char *, int);
97020474
SP
27
28char *
16f87cfd 29generic_rawmemchr (const char *s, int c)
97020474 30{
16f87cfd
WD
31 if (c != 0)
32 return memchr (s, c, PTRDIFF_MAX);
33 return (char *)s + strlen (s);
97020474
SP
34}
35
16f87cfd
WD
36IMPL (rawmemchr, 1)
37IMPL (generic_rawmemchr, 0)
38
97020474
SP
39static void
40do_one_test (impl_t *impl, const char *s, int c, char *exp_res)
41{
44558701
WN
42 size_t i, iters = INNER_LOOP_ITERS;
43 timing_t start, stop, cur;
97020474
SP
44 char *res = CALL (impl, s, c);
45 if (res != exp_res)
46 {
47 error (0, 0, "Wrong result in function %s %p %p", impl->name,
48 res, exp_res);
49 ret = 1;
50 return;
51 }
52
44558701
WN
53 TIMING_NOW (start);
54 for (i = 0; i < iters; ++i)
97020474 55 {
44558701 56 CALL (impl, s, c);
97020474 57 }
44558701
WN
58 TIMING_NOW (stop);
59
60 TIMING_DIFF (cur, start, stop);
61
62 TIMING_PRINT_MEAN ((double) cur, (double) iters);
97020474
SP
63}
64
65static void
66do_test (size_t align, size_t pos, size_t len, int seek_char)
67{
68 size_t i;
69 char *result;
70
71 align &= 7;
72 if (align + len >= page_size)
73 return;
74
75 for (i = 0; i < len; ++i)
76 {
77 buf1[align + i] = 1 + 23 * i % 127;
78 if (buf1[align + i] == seek_char)
79 buf1[align + i] = seek_char + 1;
80 }
81 buf1[align + len] = 0;
82
83 assert (pos < len);
84
85 buf1[align + pos] = seek_char;
86 buf1[align + len] = -seek_char;
87 result = (char *) (buf1 + align + pos);
88
44558701 89 printf ("Length %4zd, alignment %2zd:", pos, align);
97020474
SP
90
91 FOR_EACH_IMPL (impl, 0)
92 do_one_test (impl, (char *) (buf1 + align), seek_char, result);
93
44558701 94 putchar ('\n');
97020474
SP
95}
96
97int
98test_main (void)
99{
100 size_t i;
101
102 test_init ();
103
104 printf ("%20s", "");
105 FOR_EACH_IMPL (impl, 0)
106 printf ("\t%s", impl->name);
107 putchar ('\n');
108
109 for (i = 1; i < 7; ++i)
110 {
111 do_test (0, 16 << i, 2048, 23);
112 do_test (i, 64, 256, 23);
113 do_test (0, 16 << i, 2048, 0);
114 do_test (i, 64, 256, 0);
115 }
116 for (i = 1; i < 32; ++i)
117 {
118 do_test (0, i, i + 1, 23);
119 do_test (0, i, i + 1, 0);
120 }
121
122 return ret;
123}
124
b598e134 125#include <support/test-driver.c>