1/* Measure memset function throughput with large data sizes.
2 Copyright (C) 2017-2022 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#define TEST_NAME "memset"
21#define START_SIZE 128
22#define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
23#define TIMEOUT (20 * 60)
24#include "bench-string.h"
25
26#include "json-lib.h"
27
28void *generic_memset (void *, int, size_t);
29typedef void *(*proto_t) (void *, int, size_t);
30
31IMPL (MEMSET, 1)
32IMPL (generic_memset, 0)
33
34static void
35do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
36 int c __attribute ((unused)), size_t n)
37{
38 size_t i, iters = MIN_PAGE_SIZE / n;
39 timing_t start, stop, cur;
40
41 TIMING_NOW (start);
42 for (i = 0; i < iters && s <= s_end; s_end -= n, i++)
43 CALL (impl, s, c, n);
44 TIMING_NOW (stop);
45
46 TIMING_DIFF (cur, start, stop);
47
48 /* Get time taken per function call. */
49 json_element_double (ctx: json_ctx, d: (double) cur / i);
50}
51
52static void
53do_test (json_ctx_t *json_ctx, int c, size_t len)
54{
55 json_element_object_begin (ctx: json_ctx);
56 json_attr_uint (ctx: json_ctx, name: "length", d: len);
57 json_attr_uint (ctx: json_ctx, name: "char", d: c);
58 json_array_begin (ctx: json_ctx, name: "timings");
59
60 FOR_EACH_IMPL (impl, 0)
61 {
62 do_one_test (json_ctx, impl, s: (CHAR *) buf1,
63 s_end: (CHAR *) buf1 + MIN_PAGE_SIZE - len, c, n: len);
64 alloc_bufs ();
65 }
66
67 json_array_end (ctx: json_ctx);
68 json_element_object_end (ctx: json_ctx);
69}
70
71int
72test_main (void)
73{
74 json_ctx_t json_ctx;
75 size_t i;
76
77 test_init ();
78
79 json_init (ctx: &json_ctx, indent_level: 0, stdout);
80
81 json_document_begin (ctx: &json_ctx);
82 json_attr_string (ctx: &json_ctx, name: "timing_type", TIMING_TYPE);
83
84 json_attr_object_begin (ctx: &json_ctx, name: "functions");
85 json_attr_object_begin (ctx: &json_ctx, TEST_NAME);
86 json_attr_string (ctx: &json_ctx, name: "bench-variant", s: "walk");
87
88 json_array_begin (ctx: &json_ctx, name: "ifuncs");
89 FOR_EACH_IMPL (impl, 0)
90 json_element_string (ctx: &json_ctx, s: impl->name);
91 json_array_end (ctx: &json_ctx);
92
93 json_array_begin (ctx: &json_ctx, name: "results");
94 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
95 {
96 do_test (json_ctx: &json_ctx, c: 65, len: i);
97 do_test (json_ctx: &json_ctx, c: 65, len: i + 1);
98 }
99
100 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
101 {
102 do_test (json_ctx: &json_ctx, c: 0, len: i);
103 do_test (json_ctx: &json_ctx, c: 0, len: i + 1);
104 }
105
106 json_array_end (ctx: &json_ctx);
107 json_attr_object_end (ctx: &json_ctx);
108 json_attr_object_end (ctx: &json_ctx);
109 json_document_end (ctx: &json_ctx);
110
111 return ret;
112}
113
114#include <support/test-driver.c>
115
116#define libc_hidden_builtin_def(X)
117#define libc_hidden_def(X)
118#define libc_hidden_weak(X)
119#define weak_alias(X,Y)
120#undef MEMSET
121#define MEMSET generic_memset
122#include <string/memset.c>
123

source code of glibc/benchtests/bench-memset-walk.c