Reorganize and revise NEWS for 2.26.
[glibc.git] / benchtests / bench-memcpy-large.c
blobae5e819635ce360cebf4168cdee33e8380909f51
1 /* Measure memcpy 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 #ifndef MEMCPY_RESULT
20 # define MEMCPY_RESULT(dst, len) dst
21 # define START_SIZE (64 * 1024)
22 # define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
23 # define TEST_MAIN
24 # define TEST_NAME "memcpy"
25 # define TIMEOUT (20 * 60)
26 # include "bench-string.h"
28 IMPL (memcpy, 1)
29 #endif
31 #include "json-lib.h"
33 typedef char *(*proto_t) (char *, const char *, size_t);
35 static void
36 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
37 size_t len)
39 size_t i, iters = 16;
40 timing_t start, stop, cur;
42 /* Must clear the destination buffer updated by the previous run. */
43 for (i = 0; i < len; i++)
44 dst[i] = 0;
46 if (CALL (impl, dst, src, len) != MEMCPY_RESULT (dst, len))
48 error (0, 0, "Wrong result in function %s %p %p", impl->name,
49 CALL (impl, dst, src, len), MEMCPY_RESULT (dst, len));
50 ret = 1;
51 return;
54 if (memcmp (dst, src, len) != 0)
56 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
57 impl->name, dst, src);
58 ret = 1;
59 return;
62 TIMING_NOW (start);
63 for (i = 0; i < iters; ++i)
65 CALL (impl, dst, src, len);
67 TIMING_NOW (stop);
69 TIMING_DIFF (cur, start, stop);
71 json_element_double (json_ctx, (double) cur / (double) iters);
74 static void
75 do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
77 size_t i, j;
78 char *s1, *s2;
80 align1 &= 63;
81 if (align1 + len >= page_size)
82 return;
84 align2 &= 63;
85 if (align2 + len >= page_size)
86 return;
88 s1 = (char *) (buf1 + align1);
89 s2 = (char *) (buf2 + align2);
91 for (i = 0, j = 1; i < len; i++, j += 23)
92 s1[i] = j;
94 json_element_object_begin (json_ctx);
95 json_attr_uint (json_ctx, "length", (double) len);
96 json_attr_uint (json_ctx, "align1", (double) align1);
97 json_attr_uint (json_ctx, "align2", (double) align2);
98 json_array_begin (json_ctx, "timings");
100 FOR_EACH_IMPL (impl, 0)
101 do_one_test (json_ctx, impl, s2, s1, len);
103 json_array_end (json_ctx);
104 json_element_object_end (json_ctx);
108 test_main (void)
110 json_ctx_t json_ctx;
111 size_t i;
113 test_init ();
115 json_init (&json_ctx, 0, stdout);
117 json_document_begin (&json_ctx);
118 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
120 json_attr_object_begin (&json_ctx, "functions");
121 json_attr_object_begin (&json_ctx, "memcpy");
122 json_attr_string (&json_ctx, "bench-variant", "large");
124 json_array_begin (&json_ctx, "ifuncs");
125 FOR_EACH_IMPL (impl, 0)
126 json_element_string (&json_ctx, impl->name);
127 json_array_end (&json_ctx);
129 json_array_begin (&json_ctx, "results");
130 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
132 do_test (&json_ctx, 0, 0, i + 7);
133 do_test (&json_ctx, 0, 3, i + 15);
134 do_test (&json_ctx, 3, 0, i + 31);
135 do_test (&json_ctx, 3, 5, i + 63);
138 json_array_end (&json_ctx);
139 json_attr_object_end (&json_ctx);
140 json_attr_object_end (&json_ctx);
141 json_document_end (&json_ctx);
143 return ret;
146 #include <support/test-driver.c>