]>
Commit | Line | Data |
---|---|---|
a25322f4 L |
1 | /* Measure memmove 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 BASE_PAGE_SIZE (1024 * 1024) | |
20 | #define START_SIZE (4 * 1024) | |
21 | #define MIN_PAGE_SIZE (getpagesize () + 16 * 1024 * 1024) | |
22 | #define TEST_MAIN | |
23 | #define TEST_NAME "memmove" | |
24 | #define TIMEOUT (20 * 60) | |
25 | #include "bench-string.h" | |
26 | ||
27 | IMPL (memmove, 1) | |
28 | ||
29 | typedef char *(*proto_t) (char *, const char *, size_t); | |
30 | ||
31 | static void | |
32 | do_one_test (impl_t *impl, char *dst, char *src, const char *orig_src, | |
33 | size_t len) | |
34 | { | |
35 | size_t i, iters = 16; | |
36 | timing_t start, stop, cur; | |
37 | ||
38 | /* This also clears the destination buffer updated by the previous | |
39 | run. */ | |
40 | memcpy (src, orig_src, len); | |
41 | ||
42 | char *res = CALL (impl, dst, src, len); | |
43 | if (res != dst) | |
44 | { | |
45 | error (0, 0, "Wrong result in function %s %p %p", impl->name, | |
46 | res, dst); | |
47 | ret = 1; | |
48 | return; | |
49 | } | |
50 | ||
51 | if (memcmp (dst, orig_src, len) != 0) | |
52 | { | |
53 | error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"", | |
54 | impl->name, dst, src); | |
55 | ret = 1; | |
56 | return; | |
57 | } | |
58 | ||
59 | TIMING_NOW (start); | |
60 | for (i = 0; i < iters; ++i) | |
61 | { | |
62 | CALL (impl, dst, src, len); | |
63 | } | |
64 | TIMING_NOW (stop); | |
65 | ||
66 | TIMING_DIFF (cur, start, stop); | |
67 | ||
68 | TIMING_PRINT_MEAN ((double) cur, (double) iters); | |
69 | } | |
70 | ||
71 | static void | |
72 | do_test (size_t align1, size_t align2, size_t len) | |
73 | { | |
74 | size_t i, j; | |
75 | char *s1, *s2; | |
76 | ||
77 | align1 &= 127; | |
78 | if (align1 + len >= page_size) | |
79 | return; | |
80 | ||
81 | align2 &= 127; | |
82 | if (align2 + len >= page_size) | |
83 | return; | |
84 | ||
85 | s1 = (char *) (buf1 + align1); | |
86 | s2 = (char *) (buf2 + align2); | |
87 | ||
88 | for (i = 0, j = 1; i < len; i++, j += 23) | |
89 | s1[i] = j; | |
90 | ||
91 | printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2); | |
92 | ||
93 | FOR_EACH_IMPL (impl, 0) | |
94 | do_one_test (impl, s2, (char *) (buf2 + align1), s1, len); | |
95 | ||
96 | putchar ('\n'); | |
97 | } | |
98 | ||
99 | int | |
100 | test_main (void) | |
101 | { | |
102 | size_t i; | |
103 | ||
104 | test_init (); | |
105 | ||
106 | printf ("%23s", ""); | |
107 | FOR_EACH_IMPL (impl, 0) | |
108 | printf ("\t%s", impl->name); | |
109 | putchar ('\n'); | |
110 | ||
111 | for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1) | |
112 | { | |
113 | do_test (0, 64, i + 7); | |
114 | do_test (0, 3, i + 15); | |
115 | do_test (3, 0, i + 31); | |
116 | do_test (3, 7, i + 63); | |
117 | do_test (9, 5, i + 127); | |
118 | } | |
119 | ||
120 | return ret; | |
121 | } | |
122 | ||
b598e134 | 123 | #include <support/test-driver.c> |