]> git.ipfire.org Git - thirdparty/glibc.git/blob - benchtests/bench-memset.c
0df55d126352d0db20681944e73241fef4483a80
[thirdparty/glibc.git] / benchtests / bench-memset.c
1 /* Measure memset functions.
2 Copyright (C) 2013-2019 Free Software Foundation, Inc.
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 #define TEST_MAIN
20 #ifndef WIDE
21 # define TEST_NAME "memset"
22 #else
23 # define TEST_NAME "wmemset"
24 #endif /* WIDE */
25 #define MIN_PAGE_SIZE 131072
26 #include "bench-string.h"
27
28 #include "json-lib.h"
29
30 CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
31
32 typedef CHAR *(*proto_t) (CHAR *, int, size_t);
33
34 IMPL (MEMSET, 1)
35 IMPL (SIMPLE_MEMSET, 0)
36
37 CHAR *
38 inhibit_loop_to_libcall
39 SIMPLE_MEMSET (CHAR *s, int c, size_t n)
40 {
41 CHAR *r = s, *end = s + n;
42 while (r < end)
43 *r++ = c;
44 return s;
45 }
46
47 static void
48 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
49 int c __attribute ((unused)), size_t n)
50 {
51 size_t i, iters = INNER_LOOP_ITERS;
52 timing_t start, stop, cur;
53
54 TIMING_NOW (start);
55 for (i = 0; i < iters; ++i)
56 {
57 CALL (impl, s, c, n);
58 }
59 TIMING_NOW (stop);
60
61 TIMING_DIFF (cur, start, stop);
62
63 json_element_double (json_ctx, (double) cur / (double) iters);
64 }
65
66 static void
67 do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
68 {
69 align &= 63;
70 if ((align + len) * sizeof (CHAR) > page_size)
71 return;
72
73 json_element_object_begin (json_ctx);
74 json_attr_uint (json_ctx, "length", len);
75 json_attr_uint (json_ctx, "alignment", align);
76 json_attr_int (json_ctx, "char", c);
77 json_array_begin (json_ctx, "timings");
78
79 FOR_EACH_IMPL (impl, 0)
80 {
81 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
82 alloc_bufs ();
83 }
84
85 json_array_end (json_ctx);
86 json_element_object_end (json_ctx);
87 }
88
89 int
90 test_main (void)
91 {
92 json_ctx_t json_ctx;
93 size_t i;
94 int c = 0;
95
96 test_init ();
97
98 json_init (&json_ctx, 0, stdout);
99
100 json_document_begin (&json_ctx);
101 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
102
103 json_attr_object_begin (&json_ctx, "functions");
104 json_attr_object_begin (&json_ctx, TEST_NAME);
105 json_attr_string (&json_ctx, "bench-variant", "");
106
107 json_array_begin (&json_ctx, "ifuncs");
108 FOR_EACH_IMPL (impl, 0)
109 json_element_string (&json_ctx, impl->name);
110 json_array_end (&json_ctx);
111
112 json_array_begin (&json_ctx, "results");
113
114 for (c = -65; c <= 130; c += 65)
115 {
116 for (i = 0; i < 18; ++i)
117 do_test (&json_ctx, 0, c, 1 << i);
118 for (i = 1; i < 32; ++i)
119 {
120 do_test (&json_ctx, i, c, i);
121 if (i & (i - 1))
122 do_test (&json_ctx, 0, c, i);
123 }
124 for (i = 32; i < 512; i+=32)
125 {
126 do_test (&json_ctx, 0, c, i);
127 do_test (&json_ctx, i, c, i);
128 }
129 do_test (&json_ctx, 1, c, 14);
130 do_test (&json_ctx, 3, c, 1024);
131 do_test (&json_ctx, 4, c, 64);
132 do_test (&json_ctx, 2, c, 25);
133 }
134 for (i = 33; i <= 256; i += 4)
135 {
136 do_test (&json_ctx, 0, c, 32 * i);
137 do_test (&json_ctx, i, c, 32 * i);
138 }
139
140 json_array_end (&json_ctx);
141 json_attr_object_end (&json_ctx);
142 json_attr_object_end (&json_ctx);
143 json_document_end (&json_ctx);
144
145 return ret;
146 }
147
148 #include <support/test-driver.c>