1 /* Measure memcpy functions with large data sizes.
2 Copyright (C) 2016 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/>. */
20 # define MEMCPY_RESULT(dst, len) dst
21 # define START_SIZE (64 * 1024)
22 # define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
24 # define TEST_NAME "memcpy"
25 # define TIMEOUT (20 * 60)
26 # include "bench-string.h"
31 typedef char *(*proto_t
) (char *, const char *, size_t);
34 do_one_test (impl_t
*impl
, char *dst
, const char *src
,
38 timing_t start
, stop
, cur
;
40 /* Must clear the destination buffer updated by the previous run. */
41 for (i
= 0; i
< len
; i
++)
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
));
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
);
61 for (i
= 0; i
< iters
; ++i
)
63 CALL (impl
, dst
, src
, len
);
67 TIMING_DIFF (cur
, start
, stop
);
69 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
73 do_test (size_t align1
, size_t align2
, size_t len
)
79 if (align1
+ len
>= page_size
)
83 if (align2
+ len
>= page_size
)
86 s1
= (char *) (buf1
+ align1
);
87 s2
= (char *) (buf2
+ align2
);
89 for (i
= 0, j
= 1; i
< len
; i
++, j
+= 23)
92 printf ("Length %4zd, alignment %2zd/%2zd:", len
, align1
, align2
);
94 FOR_EACH_IMPL (impl
, 0)
95 do_one_test (impl
, s2
, s1
, len
);
108 FOR_EACH_IMPL (impl
, 0)
109 printf ("\t%s", impl
->name
);
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);
123 #include "../test-skeleton.c"