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