1 /* Measure memset 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/>. */
21 # define TEST_NAME "memset"
23 # define TEST_NAME "wmemset"
25 #define START_SIZE (128 * 1024)
26 #define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024)
27 #define TIMEOUT (20 * 60)
28 #include "bench-string.h"
31 # define MEMSET memset
33 # define SIMPLE_MEMSET simple_memset
34 # define MEMCMP memcmp
37 # define MEMSET wmemset
39 # define SIMPLE_MEMSET simple_wmemset
40 # define MEMCMP wmemcmp
47 typedef CHAR
*(*proto_t
) (CHAR
*, int, size_t);
50 inhibit_loop_to_libcall
51 SIMPLE_MEMSET (CHAR
*s
, int c
, size_t n
)
53 CHAR
*r
= s
, *end
= s
+ n
;
60 do_one_test (impl_t
*impl
, CHAR
*s
, int c
__attribute ((unused
)), size_t n
)
63 timing_t start
, stop
, cur
;
64 CHAR
*tstbuf
= malloc (n
* sizeof (*s
));
65 assert (tstbuf
!= NULL
);
67 /* Must clear the destination buffer updated by the previous run. */
68 for (i
= 0; i
< n
; i
++)
71 CHAR
*res
= CALL (impl
, s
, c
, n
);
73 || SIMPLE_MEMSET (tstbuf
, c
, n
) != tstbuf
74 || MEMCMP (s
, tstbuf
, n
) != 0)
76 error (0, 0, "Wrong result in function %s", impl
->name
);
83 for (i
= 0; i
< iters
; ++i
)
89 TIMING_DIFF (cur
, start
, stop
);
91 TIMING_PRINT_MEAN ((double) cur
, (double) iters
);
97 do_test (size_t align
, int c
, size_t len
)
100 if ((align
+ len
) * sizeof (CHAR
) > page_size
)
103 printf ("Length %4zd, alignment %2zd, c %2d:", len
, align
, c
);
105 FOR_EACH_IMPL (impl
, 0)
106 do_one_test (impl
, (CHAR
*) (buf1
) + align
, c
, len
);
120 FOR_EACH_IMPL (impl
, 0)
121 printf ("\t%s", impl
->name
);
125 for (i
= START_SIZE
; i
<= MIN_PAGE_SIZE
; i
<<= 1)
134 #include "../test-skeleton.c"