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