1 /* Measure bzero functions.
2 Copyright (C) 2022-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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 <https://www.gnu.org/licenses/>. */
21 # define TEST_NAME "memset"
23 # define TEST_NAME "bzero"
25 #define MIN_PAGE_SIZE 131072
26 #include "bench-string.h"
31 void *generic_memset (void *, int, size_t);
33 typedef void *(*proto_t
) (void *, int, size_t);
36 IMPL (generic_memset
, 0)
40 memset_zero (void * s
, size_t len
)
42 memset (s
, '\0', len
);
45 typedef void (*proto_t
) (void *, size_t);
52 do_one_test (json_ctx_t
*json_ctx
, impl_t
*impl
, CHAR
*s
, size_t n
)
54 size_t i
, iters
= INNER_LOOP_ITERS_LARGE
;
55 timing_t start
, stop
, cur
;
58 for (i
= 0; i
< iters
; ++i
)
68 TIMING_DIFF (cur
, start
, stop
);
70 json_element_double (json_ctx
, (double) cur
/ (double) iters
);
74 do_test (json_ctx_t
*json_ctx
, size_t align
, size_t len
)
77 if ((align
+ len
) * sizeof (CHAR
) > page_size
)
80 json_element_object_begin (json_ctx
);
81 json_attr_uint (json_ctx
, "length", len
);
82 json_attr_uint (json_ctx
, "alignment", align
);
83 json_array_begin (json_ctx
, "timings");
85 FOR_EACH_IMPL (impl
, 0)
87 do_one_test (json_ctx
, impl
, (CHAR
*) (buf1
) + align
, len
);
90 json_array_end (json_ctx
);
91 json_element_object_end (json_ctx
);
102 json_init (&json_ctx
, 0, stdout
);
104 json_document_begin (&json_ctx
);
105 json_attr_string (&json_ctx
, "timing_type", TIMING_TYPE
);
107 json_attr_object_begin (&json_ctx
, "functions");
108 json_attr_object_begin (&json_ctx
, TEST_NAME
);
109 json_attr_string (&json_ctx
, "bench-variant", "default");
111 json_array_begin (&json_ctx
, "ifuncs");
112 FOR_EACH_IMPL (impl
, 0)
113 json_element_string (&json_ctx
, impl
->name
);
114 json_array_end (&json_ctx
);
116 json_array_begin (&json_ctx
, "results");
118 for (i
= 0; i
< 18; ++i
)
119 do_test (&json_ctx
, 0, 1 << i
);
120 for (i
= 0; i
< 64; ++i
)
122 do_test (&json_ctx
, i
, i
);
123 do_test (&json_ctx
, 4096 - i
, i
);
124 do_test (&json_ctx
, 4095, i
);
126 do_test (&json_ctx
, 0, i
);
128 for (i
= 32; i
< 1024; i
+=32)
130 do_test (&json_ctx
, 0, i
);
131 do_test (&json_ctx
, i
, i
);
133 do_test (&json_ctx
, 1, 14);
134 do_test (&json_ctx
, 3, 1024);
135 do_test (&json_ctx
, 4, 64);
136 do_test (&json_ctx
, 2, 25);
138 for (i
= 33; i
<= 256; i
+= 4)
140 do_test (&json_ctx
, 0, 32 * i
);
141 do_test (&json_ctx
, i
, 32 * i
);
144 json_array_end (&json_ctx
);
145 json_attr_object_end (&json_ctx
);
146 json_attr_object_end (&json_ctx
);
147 json_document_end (&json_ctx
);
152 #include <support/test-driver.c>
155 # define libc_hidden_builtin_def(X)
156 # define libc_hidden_def(X)
157 # define libc_hidden_weak(X)
158 # define weak_alias(X,Y)
160 # define MEMSET generic_memset
161 # include <string/memset.c>