]>
Commit | Line | Data |
---|---|---|
c1f75dc3 | 1 | /* Measure memcpy functions. |
04277e02 | 2 | Copyright (C) 2013-2019 Free Software Foundation, Inc. |
c1f75dc3 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 | #ifndef MEMCPY_RESULT | |
20 | # define MEMCPY_RESULT(dst, len) dst | |
21 | # define MIN_PAGE_SIZE 131072 | |
22 | # define TEST_MAIN | |
23 | # define TEST_NAME "memcpy" | |
24 | # include "bench-string.h" | |
25 | ||
c1f75dc3 SP |
26 | char * |
27 | simple_memcpy (char *dst, const char *src, size_t n) | |
28 | { | |
29 | char *ret = dst; | |
30 | while (n--) | |
31 | *dst++ = *src++; | |
32 | return ret; | |
33 | } | |
34 | ||
16f87cfd WD |
35 | IMPL (memcpy, 1) |
36 | IMPL (simple_memcpy, 0) | |
37 | ||
c1f75dc3 SP |
38 | #endif |
39 | ||
5ee1e3ce SP |
40 | # include "json-lib.h" |
41 | ||
c1f75dc3 SP |
42 | typedef char *(*proto_t) (char *, const char *, size_t); |
43 | ||
44 | static void | |
5ee1e3ce | 45 | do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src, |
c1f75dc3 SP |
46 | size_t len) |
47 | { | |
44558701 WN |
48 | size_t i, iters = INNER_LOOP_ITERS; |
49 | timing_t start, stop, cur; | |
50 | ||
44558701 WN |
51 | TIMING_NOW (start); |
52 | for (i = 0; i < iters; ++i) | |
c1f75dc3 | 53 | { |
44558701 | 54 | CALL (impl, dst, src, len); |
c1f75dc3 | 55 | } |
44558701 WN |
56 | TIMING_NOW (stop); |
57 | ||
58 | TIMING_DIFF (cur, start, stop); | |
59 | ||
5ee1e3ce | 60 | json_element_double (json_ctx, (double) cur / (double) iters); |
c1f75dc3 SP |
61 | } |
62 | ||
63 | static void | |
5ee1e3ce | 64 | do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len) |
c1f75dc3 SP |
65 | { |
66 | size_t i, j; | |
67 | char *s1, *s2; | |
68 | ||
69 | align1 &= 63; | |
70 | if (align1 + len >= page_size) | |
71 | return; | |
72 | ||
73 | align2 &= 63; | |
74 | if (align2 + len >= page_size) | |
75 | return; | |
76 | ||
77 | s1 = (char *) (buf1 + align1); | |
78 | s2 = (char *) (buf2 + align2); | |
79 | ||
80 | for (i = 0, j = 1; i < len; i++, j += 23) | |
81 | s1[i] = j; | |
82 | ||
5ee1e3ce SP |
83 | json_element_object_begin (json_ctx); |
84 | json_attr_uint (json_ctx, "length", (double) len); | |
85 | json_attr_uint (json_ctx, "align1", (double) align1); | |
86 | json_attr_uint (json_ctx, "align2", (double) align2); | |
87 | json_array_begin (json_ctx, "timings"); | |
c1f75dc3 SP |
88 | |
89 | FOR_EACH_IMPL (impl, 0) | |
5ee1e3ce | 90 | do_one_test (json_ctx, impl, s2, s1, len); |
c1f75dc3 | 91 | |
5ee1e3ce SP |
92 | json_array_end (json_ctx); |
93 | json_element_object_end (json_ctx); | |
c1f75dc3 SP |
94 | } |
95 | ||
96 | int | |
97 | test_main (void) | |
98 | { | |
5ee1e3ce | 99 | json_ctx_t json_ctx; |
c1f75dc3 SP |
100 | size_t i; |
101 | ||
102 | test_init (); | |
103 | ||
5ee1e3ce SP |
104 | json_init (&json_ctx, 0, stdout); |
105 | ||
106 | json_document_begin (&json_ctx); | |
107 | json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); | |
108 | ||
109 | json_attr_object_begin (&json_ctx, "functions"); | |
7ee38e60 | 110 | json_attr_object_begin (&json_ctx, TEST_NAME); |
5ee1e3ce SP |
111 | json_attr_string (&json_ctx, "bench-variant", "default"); |
112 | ||
113 | json_array_begin (&json_ctx, "ifuncs"); | |
c1f75dc3 | 114 | FOR_EACH_IMPL (impl, 0) |
5ee1e3ce SP |
115 | json_element_string (&json_ctx, impl->name); |
116 | json_array_end (&json_ctx); | |
c1f75dc3 | 117 | |
5ee1e3ce | 118 | json_array_begin (&json_ctx, "results"); |
c1f75dc3 SP |
119 | for (i = 0; i < 18; ++i) |
120 | { | |
5ee1e3ce SP |
121 | do_test (&json_ctx, 0, 0, 1 << i); |
122 | do_test (&json_ctx, i, 0, 1 << i); | |
123 | do_test (&json_ctx, 0, i, 1 << i); | |
124 | do_test (&json_ctx, i, i, 1 << i); | |
c1f75dc3 SP |
125 | } |
126 | ||
127 | for (i = 0; i < 32; ++i) | |
128 | { | |
5ee1e3ce SP |
129 | do_test (&json_ctx, 0, 0, i); |
130 | do_test (&json_ctx, i, 0, i); | |
131 | do_test (&json_ctx, 0, i, i); | |
132 | do_test (&json_ctx, i, i, i); | |
c1f75dc3 SP |
133 | } |
134 | ||
135 | for (i = 3; i < 32; ++i) | |
136 | { | |
137 | if ((i & (i - 1)) == 0) | |
138 | continue; | |
5ee1e3ce SP |
139 | do_test (&json_ctx, 0, 0, 16 * i); |
140 | do_test (&json_ctx, i, 0, 16 * i); | |
141 | do_test (&json_ctx, 0, i, 16 * i); | |
142 | do_test (&json_ctx, i, i, 16 * i); | |
c1f75dc3 SP |
143 | } |
144 | ||
32b28d24 L |
145 | for (i = 32; i < 64; ++i) |
146 | { | |
5ee1e3ce SP |
147 | do_test (&json_ctx, 0, 0, 32 * i); |
148 | do_test (&json_ctx, i, 0, 32 * i); | |
149 | do_test (&json_ctx, 0, i, 32 * i); | |
150 | do_test (&json_ctx, i, i, 32 * i); | |
32b28d24 L |
151 | } |
152 | ||
5ee1e3ce SP |
153 | do_test (&json_ctx, 0, 0, getpagesize ()); |
154 | ||
155 | json_array_end (&json_ctx); | |
156 | json_attr_object_end (&json_ctx); | |
157 | json_attr_object_end (&json_ctx); | |
158 | json_document_end (&json_ctx); | |
c1f75dc3 SP |
159 | |
160 | return ret; | |
161 | } | |
162 | ||
b598e134 | 163 | #include <support/test-driver.c> |