linux: Avoid shifting a negative signed on POSIX timer interface
[glibc.git] / benchtests / bench-memset-large.c
blob0ea1e3811b1266daa4acf310d1a6a6630555edeb
1 /* Measure memset functions with large data sizes.
2 Copyright (C) 2016-2022 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/>. */
19 #define TEST_MAIN
20 #define TEST_NAME "memset"
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"
26 #include "json-lib.h"
28 void *generic_memset (void *, int, size_t);
29 typedef void *(*proto_t) (void *, int, size_t);
31 IMPL (MEMSET, 1)
32 IMPL (generic_memset, 0)
34 static void
35 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
36 int c __attribute ((unused)), size_t n)
38 size_t i, iters = 16;
39 timing_t start, stop, cur;
41 TIMING_NOW (start);
42 for (i = 0; i < iters; ++i)
44 CALL (impl, s, c, n);
46 TIMING_NOW (stop);
48 TIMING_DIFF (cur, start, stop);
50 json_element_double (json_ctx, (double) cur / (double) iters);
53 static void
54 do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
56 align &= 63;
57 if ((align + len) * sizeof (CHAR) > page_size)
58 return;
60 json_element_object_begin (json_ctx);
61 json_attr_uint (json_ctx, "length", len);
62 json_attr_uint (json_ctx, "alignment", align);
63 json_attr_int (json_ctx, "char", c);
64 json_array_begin (json_ctx, "timings");
66 FOR_EACH_IMPL (impl, 0)
68 do_one_test (json_ctx, impl, (CHAR *) (buf1) + align, c, len);
69 alloc_bufs ();
72 json_array_end (json_ctx);
73 json_element_object_end (json_ctx);
76 int
77 test_main (void)
79 json_ctx_t json_ctx;
80 size_t i;
81 int c;
83 test_init ();
85 json_init (&json_ctx, 0, stdout);
87 json_document_begin (&json_ctx);
88 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
90 json_attr_object_begin (&json_ctx, "functions");
91 json_attr_object_begin (&json_ctx, TEST_NAME);
92 json_attr_string (&json_ctx, "bench-variant", "large");
94 json_array_begin (&json_ctx, "ifuncs");
95 FOR_EACH_IMPL (impl, 0)
96 json_element_string (&json_ctx, impl->name);
97 json_array_end (&json_ctx);
99 json_array_begin (&json_ctx, "results");
101 c = 65;
102 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
104 do_test (&json_ctx, 0, c, i);
105 do_test (&json_ctx, 3, c, i);
108 json_array_end (&json_ctx);
109 json_attr_object_end (&json_ctx);
110 json_attr_object_end (&json_ctx);
111 json_document_end (&json_ctx);
113 return ret;
116 #include <support/test-driver.c>
118 #define libc_hidden_builtin_def(X)
119 #define libc_hidden_def(X)
120 #define libc_hidden_weak(X)
121 #define weak_alias(X,Y)
122 #undef MEMSET
123 #define MEMSET generic_memset
124 #include <string/memset.c>