1/* Measure bzero functions with large data sizes.
2 Copyright (C) 2022-2024 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 <https://www.gnu.org/licenses/>. */
18
19#define TEST_MAIN
20#ifdef DO_MEMSET
21# define TEST_NAME "memset"
22#else
23# define TEST_NAME "bzero"
24#endif
25#define START_SIZE (128 * 1024)
26#define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024)
27#define TIMEOUT (20 * 60)
28#include "bench-string.h"
29
30#include "json-lib.h"
31
32#ifdef DO_MEMSET
33void *generic_memset (void *, int, size_t);
34
35typedef void *(*proto_t) (void *, int, size_t);
36
37IMPL (memset, 1)
38IMPL (generic_memset, 0)
39#else
40static void
41memset_zero (void * s, size_t len)
42{
43 memset (s, '\0', len);
44}
45
46typedef void (*proto_t) (void *, size_t);
47
48IMPL (bzero, 1)
49IMPL (memset_zero, 0)
50#endif
51
52static void
53do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n)
54{
55 size_t i, iters = 16;
56 timing_t start, stop, cur;
57
58 TIMING_NOW (start);
59 for (i = 0; i < iters; ++i)
60 {
61#ifdef DO_MEMSET
62 CALL (impl, s, 0, n);
63#else
64 CALL (impl, s, n);
65#endif
66 }
67 TIMING_NOW (stop);
68
69 TIMING_DIFF (cur, start, stop);
70
71 json_element_double (ctx: json_ctx, d: (double) cur / (double) iters);
72}
73
74static void
75do_test (json_ctx_t *json_ctx, size_t align, size_t len)
76{
77 align &= 63;
78 if ((align + len) * sizeof (CHAR) > page_size)
79 return;
80
81 json_element_object_begin (ctx: json_ctx);
82 json_attr_uint (ctx: json_ctx, name: "length", d: len);
83 json_attr_uint (ctx: json_ctx, name: "alignment", d: align);
84 json_array_begin (ctx: json_ctx, name: "timings");
85
86 FOR_EACH_IMPL (impl, 0)
87 {
88 do_one_test (json_ctx, impl, s: (CHAR *) (buf1) + align, n: len);
89 alloc_bufs ();
90 }
91
92 json_array_end (ctx: json_ctx);
93 json_element_object_end (ctx: json_ctx);
94}
95
96int
97test_main (void)
98{
99 json_ctx_t json_ctx;
100 size_t i;
101
102 test_init ();
103
104 json_init (ctx: &json_ctx, indent_level: 0, stdout);
105
106 json_document_begin (ctx: &json_ctx);
107 json_attr_string (ctx: &json_ctx, name: "timing_type", TIMING_TYPE);
108
109 json_attr_object_begin (ctx: &json_ctx, name: "functions");
110 json_attr_object_begin (ctx: &json_ctx, TEST_NAME);
111 json_attr_string (ctx: &json_ctx, name: "bench-variant", s: "large");
112
113 json_array_begin (ctx: &json_ctx, name: "ifuncs");
114 FOR_EACH_IMPL (impl, 0)
115 json_element_string (ctx: &json_ctx, s: impl->name);
116 json_array_end (ctx: &json_ctx);
117
118 json_array_begin (ctx: &json_ctx, name: "results");
119
120 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
121 {
122 do_test (json_ctx: &json_ctx, align: 0, len: i);
123 do_test (json_ctx: &json_ctx, align: 3, len: i);
124 }
125
126 json_array_end (ctx: &json_ctx);
127 json_attr_object_end (ctx: &json_ctx);
128 json_attr_object_end (ctx: &json_ctx);
129 json_document_end (ctx: &json_ctx);
130
131 return ret;
132}
133
134#include <support/test-driver.c>
135
136#ifdef DO_MEMSET
137# define libc_hidden_builtin_def(X)
138# define libc_hidden_def(X)
139# define libc_hidden_weak(X)
140# define weak_alias(X,Y)
141# undef MEMSET
142# define MEMSET generic_memset
143# include <string/memset.c>
144#endif
145

source code of glibc/benchtests/bench-bzero-large.c