S390: Move utf8-utf32-z9.c to multiarch folder and use s390_libc_ifunc_expr macro.
[glibc.git] / benchtests / bench-memcpy-large.c
blobf50674eb5be50dd2e83e650fd3d87100e8adab50
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 typedef char *(*proto_t) (char *, const char *, size_t);
33 static void
34 do_one_test (impl_t *impl, char *dst, const char *src,
35 size_t len)
37 size_t i, iters = 16;
38 timing_t start, stop, cur;
40 /* Must clear the destination buffer updated by the previous run. */
41 for (i = 0; i < len; i++)
42 dst[i] = 0;
44 if (CALL (impl, dst, src, len) != MEMCPY_RESULT (dst, len))
46 error (0, 0, "Wrong result in function %s %p %p", impl->name,
47 CALL (impl, dst, src, len), MEMCPY_RESULT (dst, len));
48 ret = 1;
49 return;
52 if (memcmp (dst, src, len) != 0)
54 error (0, 0, "Wrong result in function %s dst \"%s\" src \"%s\"",
55 impl->name, dst, src);
56 ret = 1;
57 return;
60 TIMING_NOW (start);
61 for (i = 0; i < iters; ++i)
63 CALL (impl, dst, src, len);
65 TIMING_NOW (stop);
67 TIMING_DIFF (cur, start, stop);
69 TIMING_PRINT_MEAN ((double) cur, (double) iters);
72 static void
73 do_test (size_t align1, size_t align2, size_t len)
75 size_t i, j;
76 char *s1, *s2;
78 align1 &= 63;
79 if (align1 + len >= page_size)
80 return;
82 align2 &= 63;
83 if (align2 + len >= page_size)
84 return;
86 s1 = (char *) (buf1 + align1);
87 s2 = (char *) (buf2 + align2);
89 for (i = 0, j = 1; i < len; i++, j += 23)
90 s1[i] = j;
92 printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2);
94 FOR_EACH_IMPL (impl, 0)
95 do_one_test (impl, s2, s1, len);
97 putchar ('\n');
101 test_main (void)
103 size_t i;
105 test_init ();
107 printf ("%23s", "");
108 FOR_EACH_IMPL (impl, 0)
109 printf ("\t%s", impl->name);
110 putchar ('\n');
112 for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
114 do_test (0, 0, i + 7);
115 do_test (0, 3, i + 15);
116 do_test (3, 0, i + 31);
117 do_test (3, 5, i + 63);
120 return ret;
123 #include <support/test-driver.c>