1/* Measure memcpy functions with large data sizes.
2 Copyright (C) 2016-2022 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 <https://www.gnu.org/licenses/>. */
18
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"
27
28IMPL (memcpy, 1)
29#endif
30
31#include "json-lib.h"
32
33typedef char *(*proto_t) (char *, const char *, size_t);
34
35static void
36do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, const char *src,
37 size_t len)
38{
39 size_t i, iters = 16;
40 timing_t start, stop, cur;
41
42 TIMING_NOW (start);
43 for (i = 0; i < iters; ++i)
44 {
45 CALL (impl, dst, src, len);
46 }
47 TIMING_NOW (stop);
48
49 TIMING_DIFF (cur, start, stop);
50
51 json_element_double (ctx: json_ctx, d: (double) cur / (double) iters);
52}
53
54static void
55do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len,
56 int both_ways)
57{
58 size_t i, j;
59 char *s1, *s2;
60 size_t repeats;
61 align1 &= 4095;
62 if (align1 + len >= page_size)
63 return;
64
65 align2 &= 4095;
66 if (align2 + len >= page_size)
67 return;
68
69 s1 = (char *) (buf1 + align1);
70 s2 = (char *) (buf2 + align2);
71
72 for (repeats = both_ways ? 2 : 1; repeats; --repeats)
73 {
74 for (i = 0, j = 1; i < len; i++, j += 23)
75 s1[i] = j;
76
77 json_element_object_begin (ctx: json_ctx);
78 json_attr_uint (ctx: json_ctx, name: "length", d: (double) len);
79 json_attr_uint (ctx: json_ctx, name: "align1", d: (double) align1);
80 json_attr_uint (ctx: json_ctx, name: "align2", d: (double) align2);
81 json_attr_uint (ctx: json_ctx, name: "dst > src", d: (double) (s2 > s1));
82 json_array_begin (ctx: json_ctx, name: "timings");
83
84 FOR_EACH_IMPL (impl, 0)
85 do_one_test (json_ctx, impl, dst: s2, src: s1, len);
86
87 json_array_end (ctx: json_ctx);
88 json_element_object_end (ctx: json_ctx);
89
90 s1 = (char *) (buf2 + align1);
91 s2 = (char *) (buf1 + align2);
92 }
93}
94
95int
96test_main (void)
97{
98 json_ctx_t json_ctx;
99 size_t i;
100
101 test_init ();
102
103 json_init (ctx: &json_ctx, indent_level: 0, stdout);
104
105 json_document_begin (ctx: &json_ctx);
106 json_attr_string (ctx: &json_ctx, name: "timing_type", TIMING_TYPE);
107
108 json_attr_object_begin (ctx: &json_ctx, name: "functions");
109 json_attr_object_begin (ctx: &json_ctx, TEST_NAME);
110 json_attr_string (ctx: &json_ctx, name: "bench-variant", s: "large");
111
112 json_array_begin (ctx: &json_ctx, name: "ifuncs");
113 FOR_EACH_IMPL (impl, 0)
114 json_element_string (ctx: &json_ctx, s: impl->name);
115 json_array_end (ctx: &json_ctx);
116
117 json_array_begin (ctx: &json_ctx, name: "results");
118 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
119 {
120 do_test (json_ctx: &json_ctx, align1: 0, align2: 0, len: i + 7, both_ways: 1);
121 do_test (json_ctx: &json_ctx, align1: 0, align2: 3, len: i + 15, both_ways: 1);
122 do_test (json_ctx: &json_ctx, align1: 3, align2: 0, len: i + 31, both_ways: 1);
123 do_test (json_ctx: &json_ctx, align1: 3, align2: 5, len: i + 63, both_ways: 1);
124 do_test (json_ctx: &json_ctx, align1: 0, align2: 127, len: i, both_ways: 1);
125 do_test (json_ctx: &json_ctx, align1: 0, align2: 255, len: i, both_ways: 1);
126 do_test (json_ctx: &json_ctx, align1: 0, align2: 256, len: i, both_ways: 1);
127 do_test (json_ctx: &json_ctx, align1: 0, align2: 4064, len: i, both_ways: 1);
128 }
129
130 json_array_end (ctx: &json_ctx);
131 json_attr_object_end (ctx: &json_ctx);
132 json_attr_object_end (ctx: &json_ctx);
133 json_document_end (ctx: &json_ctx);
134
135 return ret;
136}
137
138#include <support/test-driver.c>
139

source code of glibc/benchtests/bench-memcpy-large.c