]> git.ipfire.org Git - thirdparty/glibc.git/blame - benchtests/bench-memmove.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / benchtests / bench-memmove.c
CommitLineData
97020474 1/* Measure memmove functions.
04277e02 2 Copyright (C) 2013-2019 Free Software Foundation, Inc.
97020474
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
5a82c748 17 <https://www.gnu.org/licenses/>. */
97020474
SP
18
19#define TEST_MAIN
16f87cfd 20#define TEST_NAME "memmove"
97020474 21#include "bench-string.h"
86c6519e 22#include "json-lib.h"
97020474 23
3c05dd79 24void *generic_memmove (void *, const void *, size_t);
97020474 25
3c05dd79 26typedef void *(*proto_t) (void *, const void *, size_t);
97020474 27
97020474 28IMPL (memmove, 1)
3c05dd79 29IMPL (generic_memmove, 0)
97020474
SP
30
31static void
24ca04fe
SP
32do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
33 size_t len)
97020474 34{
44558701
WN
35 size_t i, iters = INNER_LOOP_ITERS;
36 timing_t start, stop, cur;
37
44558701
WN
38 TIMING_NOW (start);
39 for (i = 0; i < iters; ++i)
97020474 40 {
44558701 41 CALL (impl, dst, src, len);
97020474 42 }
44558701
WN
43 TIMING_NOW (stop);
44
45 TIMING_DIFF (cur, start, stop);
46
86c6519e 47 json_element_double (json_ctx, (double) cur / (double) iters);
97020474
SP
48}
49
50static void
86c6519e 51do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
97020474
SP
52{
53 size_t i, j;
54 char *s1, *s2;
55
56 align1 &= 63;
57 if (align1 + len >= page_size)
58 return;
59
60 align2 &= 63;
61 if (align2 + len >= page_size)
62 return;
63
24ca04fe 64 s1 = (char *) (buf2 + align1);
97020474
SP
65 s2 = (char *) (buf2 + align2);
66
67 for (i = 0, j = 1; i < len; i++, j += 23)
68 s1[i] = j;
69
86c6519e
SP
70 json_element_object_begin (json_ctx);
71 json_attr_uint (json_ctx, "length", (double) len);
72 json_attr_uint (json_ctx, "align1", (double) align1);
73 json_attr_uint (json_ctx, "align2", (double) align2);
74 json_array_begin (json_ctx, "timings");
97020474
SP
75
76 FOR_EACH_IMPL (impl, 0)
24ca04fe 77 do_one_test (json_ctx, impl, s2, s1, len);
97020474 78
86c6519e
SP
79 json_array_end (json_ctx);
80 json_element_object_end (json_ctx);
97020474
SP
81}
82
b598e134 83static int
97020474
SP
84test_main (void)
85{
86c6519e 86 json_ctx_t json_ctx;
97020474
SP
87 size_t i;
88
89 test_init ();
90
86c6519e
SP
91 json_init (&json_ctx, 0, stdout);
92
93 json_document_begin (&json_ctx);
94 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
95
96 json_attr_object_begin (&json_ctx, "functions");
97 json_attr_object_begin (&json_ctx, "memmove");
98 json_attr_string (&json_ctx, "bench-variant", "default");
99
100 json_array_begin (&json_ctx, "ifuncs");
101
97020474 102 FOR_EACH_IMPL (impl, 0)
86c6519e
SP
103 json_element_string (&json_ctx, impl->name);
104 json_array_end (&json_ctx);
97020474 105
86c6519e 106 json_array_begin (&json_ctx, "results");
97020474
SP
107 for (i = 0; i < 14; ++i)
108 {
86c6519e
SP
109 do_test (&json_ctx, 0, 32, 1 << i);
110 do_test (&json_ctx, 32, 0, 1 << i);
111 do_test (&json_ctx, 0, i, 1 << i);
112 do_test (&json_ctx, i, 0, 1 << i);
97020474
SP
113 }
114
115 for (i = 0; i < 32; ++i)
116 {
86c6519e
SP
117 do_test (&json_ctx, 0, 32, i);
118 do_test (&json_ctx, 32, 0, i);
119 do_test (&json_ctx, 0, i, i);
120 do_test (&json_ctx, i, 0, i);
97020474
SP
121 }
122
123 for (i = 3; i < 32; ++i)
124 {
125 if ((i & (i - 1)) == 0)
126 continue;
86c6519e
SP
127 do_test (&json_ctx, 0, 32, 16 * i);
128 do_test (&json_ctx, 32, 0, 16 * i);
129 do_test (&json_ctx, 0, i, 16 * i);
130 do_test (&json_ctx, i, 0, 16 * i);
97020474
SP
131 }
132
aea44bf6
L
133 for (i = 32; i < 64; ++i)
134 {
86c6519e
SP
135 do_test (&json_ctx, 0, 0, 32 * i);
136 do_test (&json_ctx, i, 0, 32 * i);
137 do_test (&json_ctx, 0, i, 32 * i);
138 do_test (&json_ctx, i, i, 32 * i);
aea44bf6
L
139 }
140
86c6519e
SP
141 json_array_end (&json_ctx);
142 json_attr_object_end (&json_ctx);
143 json_attr_object_end (&json_ctx);
144 json_document_end (&json_ctx);
145
97020474
SP
146 return ret;
147}
148
b598e134 149#include <support/test-driver.c>
3c05dd79
WD
150
151#define libc_hidden_builtin_def(X)
152#undef MEMMOVE
153#define MEMMOVE generic_memmove
154#include <string/memmove.c>
155#include <string/wordcopy.c>