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