]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-memset.c
Improve string benchtests
[thirdparty/glibc.git] / benchtests / bench-memset.c
CommitLineData
97020474 1/* Measure memset 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#define TEST_MAIN
2e9e1667 20#ifndef WIDE
16f87cfd 21# define TEST_NAME "memset"
2e9e1667 22#else
16f87cfd 23# define TEST_NAME "wmemset"
2e9e1667 24#endif /* WIDE */
16f87cfd
WD
25#define MIN_PAGE_SIZE 131072
26#include "bench-string.h"
2e9e1667 27
29c933fb
SP
28#include "json-lib.h"
29
2e9e1667 30CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
97020474 31
2e9e1667 32typedef CHAR *(*proto_t) (CHAR *, int, size_t);
97020474 33
2e9e1667 34IMPL (MEMSET, 1)
16f87cfd 35IMPL (SIMPLE_MEMSET, 0)
97020474 36
2e9e1667 37CHAR *
85c2e611 38inhibit_loop_to_libcall
2e9e1667 39SIMPLE_MEMSET (CHAR *s, int c, size_t n)
97020474 40{
2e9e1667 41 CHAR *r = s, *end = s + n;
97020474
SP
42 while (r < end)
43 *r++ = c;
44 return s;
45}
46
47static void
29c933fb
SP
48do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
49 int c __attribute ((unused)), size_t n)
97020474 50{
44558701
WN
51 size_t i, iters = INNER_LOOP_ITERS;
52 timing_t start, stop, cur;
97020474 53
44558701
WN
54 TIMING_NOW (start);
55 for (i = 0; i < iters; ++i)
97020474 56 {
44558701 57 CALL (impl, s, c, n);
44558701
WN
58 }
59 TIMING_NOW (stop);
97020474 60
44558701 61 TIMING_DIFF (cur, start, stop);
97020474 62
29c933fb 63 json_element_double (json_ctx, (double) cur / (double) iters);
97020474
SP
64}
65
66static void
29c933fb 67do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
97020474 68{
344303f3 69 align &= 63;
2e9e1667 70 if ((align + len) * sizeof (CHAR) > page_size)
97020474
SP
71 return;
72
29c933fb
SP
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");
97020474
SP
78
79 FOR_EACH_IMPL (impl, 0)
503c92c3
SP
80 {
81 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
014efdd7 82 alloc_bufs ();
503c92c3 83 }
97020474 84
29c933fb
SP
85 json_array_end (json_ctx);
86 json_element_object_end (json_ctx);
97020474
SP
87}
88
89int
90test_main (void)
91{
29c933fb 92 json_ctx_t json_ctx;
97020474
SP
93 size_t i;
94 int c = 0;
95
96 test_init ();
97
29c933fb
SP
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");
97020474 108 FOR_EACH_IMPL (impl, 0)
29c933fb
SP
109 json_element_string (&json_ctx, impl->name);
110 json_array_end (&json_ctx);
111
112 json_array_begin (&json_ctx, "results");
97020474 113
97020474 114 for (c = -65; c <= 130; c += 65)
97020474
SP
115 {
116 for (i = 0; i < 18; ++i)
29c933fb 117 do_test (&json_ctx, 0, c, 1 << i);
97020474
SP
118 for (i = 1; i < 32; ++i)
119 {
29c933fb 120 do_test (&json_ctx, i, c, i);
97020474 121 if (i & (i - 1))
29c933fb 122 do_test (&json_ctx, 0, c, i);
97020474 123 }
71ae8647
AZ
124 for (i = 32; i < 512; i+=32)
125 {
29c933fb
SP
126 do_test (&json_ctx, 0, c, i);
127 do_test (&json_ctx, i, c, i);
71ae8647 128 }
29c933fb
SP
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);
97020474 133 }
344303f3
L
134 for (i = 33; i <= 256; i += 4)
135 {
29c933fb
SP
136 do_test (&json_ctx, 0, c, 32 * i);
137 do_test (&json_ctx, i, c, 32 * i);
344303f3 138 }
97020474 139
29c933fb
SP
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
97020474
SP
145 return ret;
146}
147
b598e134 148#include <support/test-driver.c>