Remove powerpc, sparc fdim inlines (bug 22987).
[glibc.git] / benchtests / bench-memcpy-walk.c
blobcaf71e51c450b863551a4c9d3c0d5554e93379b7
1 /* Measure memcpy function combined throughput for different alignments.
2 Copyright (C) 2017-2018 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 /* This microbenchmark measures the throughput of memcpy for various sizes from
20 1 byte to 32MiB, doubling every iteration and then misaligning by 0-15
21 bytes. The copies are done from source to destination and then back and the
22 source walks forward across the array and the destination walks backward by
23 one byte each, thus measuring misaligned accesses as well. The idea is to
24 avoid caching effects by copying a different string and far enough from each
25 other, walking in different directions so that we can measure prefetcher
26 efficiency (software or hardware) more closely than with a loop copying the
27 same data over and over, which eventually only gives us L1 cache
28 performance. */
30 #ifndef MEMCPY_RESULT
31 # define MEMCPY_RESULT(dst, len) dst
32 # define START_SIZE 128
33 # define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
34 # define TEST_MAIN
35 # define TEST_NAME "memcpy"
36 # define TIMEOUT (20 * 60)
37 # include "bench-string.h"
39 IMPL (memcpy, 1)
40 #endif
42 #include "json-lib.h"
44 typedef char *(*proto_t) (char *, const char *, size_t);
46 static void
47 do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
48 size_t len)
50 size_t i = 0;
51 timing_t start, stop, cur;
53 char *dst_end = dst + MIN_PAGE_SIZE - len;
54 char *src_end = src + MIN_PAGE_SIZE - len;
56 TIMING_NOW (start);
57 /* Copy the entire buffer backwards, LEN at a time. */
58 for (; src_end >= src && dst_end >= dst; src_end -= len, dst_end -= len, i++)
59 CALL (impl, src_end, dst_end, len);
60 TIMING_NOW (stop);
62 TIMING_DIFF (cur, start, stop);
64 /* Get time taken per function call. */
65 json_element_double (json_ctx, (double) cur / i);
68 static void
69 do_test (json_ctx_t *json_ctx, size_t len)
71 json_element_object_begin (json_ctx);
72 json_attr_uint (json_ctx, "length", (double) len);
73 json_array_begin (json_ctx, "timings");
75 FOR_EACH_IMPL (impl, 0)
76 do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, len);
78 json_array_end (json_ctx);
79 json_element_object_end (json_ctx);
82 int
83 test_main (void)
85 json_ctx_t json_ctx;
86 size_t i;
88 test_init ();
90 json_init (&json_ctx, 0, stdout);
92 json_document_begin (&json_ctx);
93 json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
95 json_attr_object_begin (&json_ctx, "functions");
96 json_attr_object_begin (&json_ctx, "memcpy");
97 json_attr_string (&json_ctx, "bench-variant", "walk");
99 json_array_begin (&json_ctx, "ifuncs");
100 FOR_EACH_IMPL (impl, 0)
101 json_element_string (&json_ctx, impl->name);
102 json_array_end (&json_ctx);
104 json_array_begin (&json_ctx, "results");
105 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
107 /* Test length alignments from 0-16 bytes. */
108 for (int j = 0; j < 8; j++)
110 do_test (&json_ctx, i + j);
111 do_test (&json_ctx, i + 16 - j);
115 json_array_end (&json_ctx);
116 json_attr_object_end (&json_ctx);
117 json_attr_object_end (&json_ctx);
118 json_document_end (&json_ctx);
120 return ret;
123 #include <support/test-driver.c>