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

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