Remove TIMING_INIT
[glibc.git] / benchtests / bench-memset.c
blob0df55d126352d0db20681944e73241fef4483a80
1 /* Measure memset functions.
2 Copyright (C) 2013-2019 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/>. */
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"
28 #include "json-lib.h"
30 CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
32 typedef CHAR *(*proto_t) (CHAR *, int, size_t);
34 IMPL (MEMSET, 1)
35 IMPL (SIMPLE_MEMSET, 0)
37 CHAR *
38 inhibit_loop_to_libcall
39 SIMPLE_MEMSET (CHAR *s, int c, size_t n)
41 CHAR *r = s, *end = s + n;
42 while (r < end)
43 *r++ = c;
44 return s;
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)
51 size_t i, iters = INNER_LOOP_ITERS;
52 timing_t start, stop, cur;
54 TIMING_NOW (start);
55 for (i = 0; i < iters; ++i)
57 CALL (impl, s, c, n);
59 TIMING_NOW (stop);
61 TIMING_DIFF (cur, start, stop);
63 json_element_double (json_ctx, (double) cur / (double) iters);
66 static void
67 do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
69 align &= 63;
70 if ((align + len) * sizeof (CHAR) > page_size)
71 return;
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");
79 FOR_EACH_IMPL (impl, 0)
81 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
82 alloc_bufs ();
85 json_array_end (json_ctx);
86 json_element_object_end (json_ctx);
89 int
90 test_main (void)
92 json_ctx_t json_ctx;
93 size_t i;
94 int c = 0;
96 test_init ();
98 json_init (&json_ctx, 0, stdout);
100 json_document_begin (&json_ctx);
101 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
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", "");
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);
112 json_array_begin (&json_ctx, "results");
114 for (c = -65; c <= 130; c += 65)
116 for (i = 0; i < 18; ++i)
117 do_test (&json_ctx, 0, c, 1 << i);
118 for (i = 1; i < 32; ++i)
120 do_test (&json_ctx, i, c, i);
121 if (i & (i - 1))
122 do_test (&json_ctx, 0, c, i);
124 for (i = 32; i < 512; i+=32)
126 do_test (&json_ctx, 0, c, i);
127 do_test (&json_ctx, i, c, i);
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);
134 for (i = 33; i <= 256; i += 4)
136 do_test (&json_ctx, 0, c, 32 * i);
137 do_test (&json_ctx, i, c, 32 * i);
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);
145 return ret;
148 #include <support/test-driver.c>