]> git.ipfire.org Git - thirdparty/glibc.git/blob - benchtests/bench-memset-walk.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / benchtests / bench-memset-walk.c
1 /* Measure memset function throughput with large data sizes.
2 Copyright (C) 2017-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 START_SIZE 128
26 #define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
27 #define TIMEOUT (20 * 60)
28 #include "bench-string.h"
29
30 #ifndef WIDE
31 # define SIMPLE_MEMSET simple_memset
32 #else
33 # define SIMPLE_MEMSET simple_wmemset
34 #endif /* WIDE */
35
36 #include <assert.h>
37 #include "json-lib.h"
38
39
40 typedef CHAR *(*proto_t) (CHAR *, int, size_t);
41
42 CHAR *
43 inhibit_loop_to_libcall
44 SIMPLE_MEMSET (CHAR *s, int c, size_t n)
45 {
46 CHAR *r = s, *end = s + n;
47 while (r < end)
48 *r++ = c;
49 return s;
50 }
51
52 IMPL (SIMPLE_MEMSET, 1)
53
54 static void
55 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
56 int c __attribute ((unused)), size_t n)
57 {
58 size_t i, iters = MIN_PAGE_SIZE / n;
59 timing_t start, stop, cur;
60
61 TIMING_NOW (start);
62 for (i = 0; i < iters && s <= s_end; s_end -= n, i++)
63 CALL (impl, s, c, n);
64 TIMING_NOW (stop);
65
66 TIMING_DIFF (cur, start, stop);
67
68 /* Get time taken per function call. */
69 json_element_double (json_ctx, (double) cur / i);
70 }
71
72 static void
73 do_test (json_ctx_t *json_ctx, int c, size_t len)
74 {
75 json_element_object_begin (json_ctx);
76 json_attr_uint (json_ctx, "length", len);
77 json_attr_uint (json_ctx, "char", c);
78 json_array_begin (json_ctx, "timings");
79
80 FOR_EACH_IMPL (impl, 0)
81 {
82 do_one_test (json_ctx, impl, (CHAR *) buf1,
83 (CHAR *) buf1 + MIN_PAGE_SIZE - len, c, len);
84 alloc_bufs ();
85 }
86
87 json_array_end (json_ctx);
88 json_element_object_end (json_ctx);
89 }
90
91 int
92 test_main (void)
93 {
94 json_ctx_t json_ctx;
95 size_t i;
96
97 test_init ();
98
99 json_init (&json_ctx, 0, stdout);
100
101 json_document_begin (&json_ctx);
102 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
103
104 json_attr_object_begin (&json_ctx, "functions");
105 json_attr_object_begin (&json_ctx, TEST_NAME);
106 json_attr_string (&json_ctx, "bench-variant", "walk");
107
108 json_array_begin (&json_ctx, "ifuncs");
109 FOR_EACH_IMPL (impl, 0)
110 json_element_string (&json_ctx, impl->name);
111 json_array_end (&json_ctx);
112
113 json_array_begin (&json_ctx, "results");
114 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
115 /* Test length alignments from 0-16 bytes. */
116 for (int j = 0; j < i && j < 16; j++)
117 do_test (&json_ctx, 65, i + j);
118
119 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
120 for (int j = 0; j < i && j < 16; j++)
121 do_test (&json_ctx, 0, i + j);
122
123 json_array_end (&json_ctx);
124 json_attr_object_end (&json_ctx);
125 json_attr_object_end (&json_ctx);
126 json_document_end (&json_ctx);
127
128 return ret;
129 }
130
131 #include <support/test-driver.c>