]>
Commit | Line | Data |
---|---|---|
a25322f4 L |
1 | /* Measure memset functions with large data sizes. |
2 | Copyright (C) 2016 Free Software Foundation, Inc. | |
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> | |
44 | ||
45 | IMPL (MEMSET, 1) | |
46 | ||
47 | typedef CHAR *(*proto_t) (CHAR *, int, size_t); | |
48 | ||
49 | CHAR * | |
50 | inhibit_loop_to_libcall | |
51 | SIMPLE_MEMSET (CHAR *s, int c, size_t n) | |
52 | { | |
53 | CHAR *r = s, *end = s + n; | |
54 | while (r < end) | |
55 | *r++ = c; | |
56 | return s; | |
57 | } | |
58 | ||
59 | static void | |
60 | do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n) | |
61 | { | |
62 | size_t i, iters = 16; | |
63 | timing_t start, stop, cur; | |
64 | CHAR *tstbuf = malloc (n * sizeof (*s)); | |
65 | assert (tstbuf != NULL); | |
66 | ||
67 | /* Must clear the destination buffer updated by the previous run. */ | |
68 | for (i = 0; i < n; i++) | |
69 | s[i] = 0; | |
70 | ||
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) | |
75 | { | |
76 | error (0, 0, "Wrong result in function %s", impl->name); | |
77 | ret = 1; | |
78 | free (tstbuf); | |
79 | return; | |
80 | } | |
81 | ||
82 | TIMING_NOW (start); | |
83 | for (i = 0; i < iters; ++i) | |
84 | { | |
85 | CALL (impl, s, c, n); | |
86 | } | |
87 | TIMING_NOW (stop); | |
88 | ||
89 | TIMING_DIFF (cur, start, stop); | |
90 | ||
91 | TIMING_PRINT_MEAN ((double) cur, (double) iters); | |
92 | ||
93 | free (tstbuf); | |
94 | } | |
95 | ||
96 | static void | |
97 | do_test (size_t align, int c, size_t len) | |
98 | { | |
99 | align &= 63; | |
100 | if ((align + len) * sizeof (CHAR) > page_size) | |
101 | return; | |
102 | ||
103 | printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c); | |
104 | ||
105 | FOR_EACH_IMPL (impl, 0) | |
106 | do_one_test (impl, (CHAR *) (buf1) + align, c, len); | |
107 | ||
108 | putchar ('\n'); | |
109 | } | |
110 | ||
111 | int | |
112 | test_main (void) | |
113 | { | |
114 | size_t i; | |
115 | int c; | |
116 | ||
117 | test_init (); | |
118 | ||
119 | printf ("%24s", ""); | |
120 | FOR_EACH_IMPL (impl, 0) | |
121 | printf ("\t%s", impl->name); | |
122 | putchar ('\n'); | |
123 | ||
124 | c = 65; | |
125 | for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) | |
126 | { | |
127 | do_test (0, c, i); | |
128 | do_test (3, c, i); | |
129 | } | |
130 | ||
131 | return ret; | |
132 | } | |
133 | ||
b598e134 | 134 | #include <support/test-driver.c> |