* manual/tunables.texi: Add missing @end deftp.
[glibc.git] / benchtests / bench-memset-large.c
blob6cfe8a595157f4c7fd3cc427d610ad6d9c62a0eb
1 /* Measure memset functions with large data sizes.
2 Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>. */
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"
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 */
43 #include <assert.h>
45 IMPL (MEMSET, 1)
47 typedef CHAR *(*proto_t) (CHAR *, int, size_t);
49 CHAR *
50 inhibit_loop_to_libcall
51 SIMPLE_MEMSET (CHAR *s, int c, size_t n)
53 CHAR *r = s, *end = s + n;
54 while (r < end)
55 *r++ = c;
56 return s;
59 static void
60 do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
62 size_t i, iters = 16;
63 timing_t start, stop, cur;
64 CHAR *tstbuf = malloc (n * sizeof (*s));
65 assert (tstbuf != NULL);
67 /* Must clear the destination buffer updated by the previous run. */
68 for (i = 0; i < n; i++)
69 s[i] = 0;
71 CHAR *res = CALL (impl, s, c, n);
72 if (res != s
73 || SIMPLE_MEMSET (tstbuf, c, n) != tstbuf
74 || MEMCMP (s, tstbuf, n) != 0)
76 error (0, 0, "Wrong result in function %s", impl->name);
77 ret = 1;
78 free (tstbuf);
79 return;
82 TIMING_NOW (start);
83 for (i = 0; i < iters; ++i)
85 CALL (impl, s, c, n);
87 TIMING_NOW (stop);
89 TIMING_DIFF (cur, start, stop);
91 TIMING_PRINT_MEAN ((double) cur, (double) iters);
93 free (tstbuf);
96 static void
97 do_test (size_t align, int c, size_t len)
99 align &= 63;
100 if ((align + len) * sizeof (CHAR) > page_size)
101 return;
103 printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c);
105 FOR_EACH_IMPL (impl, 0)
106 do_one_test (impl, (CHAR *) (buf1) + align, c, len);
108 putchar ('\n');
112 test_main (void)
114 size_t i;
115 int c;
117 test_init ();
119 printf ("%24s", "");
120 FOR_EACH_IMPL (impl, 0)
121 printf ("\t%s", impl->name);
122 putchar ('\n');
124 c = 65;
125 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
127 do_test (0, c, i);
128 do_test (3, c, i);
131 return ret;
134 #include <support/test-driver.c>