]>
Commit | Line | Data |
---|---|---|
36bb8edf | 1 | /* Measure memset function throughput with large data sizes. |
688903eb | 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. |
36bb8edf 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 | |
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 */ | |
eb332f9f | 25 | #define START_SIZE 128 |
36bb8edf SP |
26 | #define MIN_PAGE_SIZE (getpagesize () + 32 * 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 | #include "json-lib.h" | |
45 | ||
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 | IMPL (SIMPLE_MEMSET, 1) | |
60 | ||
61 | static void | |
62 | do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end, | |
63 | int c __attribute ((unused)), size_t n) | |
64 | { | |
65 | size_t i, iters = MIN_PAGE_SIZE / n; | |
66 | timing_t start, stop, cur; | |
67 | ||
68 | TIMING_NOW (start); | |
4d7632ff | 69 | for (i = 0; i < iters && s <= s_end; s_end -= n, i++) |
36bb8edf SP |
70 | CALL (impl, s, c, n); |
71 | TIMING_NOW (stop); | |
72 | ||
73 | TIMING_DIFF (cur, start, stop); | |
74 | ||
75 | /* Get time taken per function call. */ | |
4d7632ff | 76 | json_element_double (json_ctx, (double) cur / i); |
36bb8edf SP |
77 | } |
78 | ||
79 | static void | |
80 | do_test (json_ctx_t *json_ctx, int c, size_t len) | |
81 | { | |
82 | json_element_object_begin (json_ctx); | |
83 | json_attr_uint (json_ctx, "length", len); | |
84 | json_attr_uint (json_ctx, "char", c); | |
85 | json_array_begin (json_ctx, "timings"); | |
86 | ||
87 | FOR_EACH_IMPL (impl, 0) | |
88 | { | |
89 | do_one_test (json_ctx, impl, (CHAR *) buf1, | |
90 | (CHAR *) buf1 + MIN_PAGE_SIZE - len, c, len); | |
91 | realloc_bufs (); | |
92 | } | |
93 | ||
94 | json_array_end (json_ctx); | |
95 | json_element_object_end (json_ctx); | |
96 | } | |
97 | ||
98 | int | |
99 | test_main (void) | |
100 | { | |
101 | json_ctx_t json_ctx; | |
102 | size_t i; | |
103 | ||
104 | test_init (); | |
105 | ||
106 | json_init (&json_ctx, 0, stdout); | |
107 | ||
108 | json_document_begin (&json_ctx); | |
109 | json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); | |
110 | ||
111 | json_attr_object_begin (&json_ctx, "functions"); | |
112 | json_attr_object_begin (&json_ctx, TEST_NAME); | |
113 | json_attr_string (&json_ctx, "bench-variant", "walk"); | |
114 | ||
115 | json_array_begin (&json_ctx, "ifuncs"); | |
116 | FOR_EACH_IMPL (impl, 0) | |
117 | json_element_string (&json_ctx, impl->name); | |
118 | json_array_end (&json_ctx); | |
119 | ||
120 | json_array_begin (&json_ctx, "results"); | |
121 | for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) | |
122 | /* Test length alignments from 0-16 bytes. */ | |
123 | for (int j = 0; j < i && j < 16; j++) | |
124 | do_test (&json_ctx, 65, i + j); | |
125 | ||
126 | for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) | |
127 | for (int j = 0; j < i && j < 16; j++) | |
128 | do_test (&json_ctx, 0, i + j); | |
129 | ||
130 | json_array_end (&json_ctx); | |
131 | json_attr_object_end (&json_ctx); | |
132 | json_attr_object_end (&json_ctx); | |
133 | json_document_end (&json_ctx); | |
134 | ||
135 | return ret; | |
136 | } | |
137 | ||
138 | #include <support/test-driver.c> |