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