benchtests: Add benches for memset with 0 value
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 9 Feb 2022 15:31:41 +0000 (07:31 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 23 Feb 2022 20:07:06 +0000 (12:07 -0800)
memset with zero as the value to set is by far the majority value (99%+
for Python3 and GCC).  Add bench-memset-zero-large.c,
bench-memset-zero-walk.c and bench-memset-zero.c to measure memset
implementations for zeroing.

Reviewed-by: Sunil K Pandey <skpgkp2@gmail.com>
benchtests/Makefile
benchtests/bench-bzero-large.c
benchtests/bench-bzero-walk.c
benchtests/bench-bzero.c
benchtests/bench-memset-zero-large.c [new file with mode: 0644]
benchtests/bench-memset-zero-walk.c [new file with mode: 0644]
benchtests/bench-memset-zero.c [new file with mode: 0644]

index 6f718fa..9b8df3b 100644 (file)
@@ -139,6 +139,9 @@ string-benchset := \
   memset \
   memset-large \
   memset-walk \
+  memset-zero \
+  memset-zero-large \
+  memset-zero-walk \
   rawmemchr \
   stpcpy \
   stpcpy_chk \
index f2e2e98..cfc7b81 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#define TEST_NAME "bzero"
+#ifdef DO_MEMSET
+# define TEST_NAME "memset"
+#else
+# define TEST_NAME "bzero"
+#endif
 #define START_SIZE (128 * 1024)
 #define MIN_PAGE_SIZE (getpagesize () + 64 * 1024 * 1024)
 #define TIMEOUT (20 * 60)
 
 #include "json-lib.h"
 
+#ifdef DO_MEMSET
+void *generic_memset (void *, int, size_t);
+
+typedef void *(*proto_t) (void *, int, size_t);
+
+IMPL (memset, 1)
+IMPL (generic_memset, 0)
+#else
 static void
 memset_zero (void * s, size_t len)
 {
@@ -35,6 +47,7 @@ typedef void (*proto_t) (void *, size_t);
 
 IMPL (bzero, 1)
 IMPL (memset_zero, 0)
+#endif
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n)
@@ -45,7 +58,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n)
   TIMING_NOW (start);
   for (i = 0; i < iters; ++i)
     {
+#ifdef DO_MEMSET
+      CALL (impl, s, 0, n);
+#else
       CALL (impl, s, n);
+#endif
     }
   TIMING_NOW (stop);
 
@@ -115,3 +132,13 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#ifdef DO_MEMSET
+# define libc_hidden_builtin_def(X)
+# define libc_hidden_def(X)
+# define libc_hidden_weak(X)
+# define weak_alias(X,Y)
+# undef MEMSET
+# define MEMSET generic_memset
+# include <string/memset.c>
+#endif
index b65d12a..00226f8 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#define TEST_NAME "bzero"
+#ifdef DO_MEMSET
+# define TEST_NAME "memset"
+#else
+# define TEST_NAME "bzero"
+#endif
 #define START_SIZE 128
 #define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
 #define TIMEOUT (20 * 60)
 
 #include "json-lib.h"
 
+#ifdef DO_MEMSET
+void *generic_memset (void *, int, size_t);
+
+typedef void *(*proto_t) (void *, int, size_t);
+
+IMPL (memset, 1)
+IMPL (generic_memset, 0)
+
+#else
 static void
 memset_zero (void * s, size_t len)
 {
@@ -35,6 +48,7 @@ typedef void (*proto_t) (void *, size_t);
 
 IMPL (bzero, 1)
 IMPL (memset_zero, 0)
+#endif
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
@@ -45,7 +59,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
 
   TIMING_NOW (start);
   for (i = 0; i < iters && s <= s_end; s_end -= n, i++)
+#ifdef DO_MEMSET
+    CALL (impl, s, 0, n);
+#else
     CALL (impl, s, n);
+#endif
   TIMING_NOW (stop);
 
   TIMING_DIFF (cur, start, stop);
@@ -116,3 +134,13 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#ifdef DO_MEMSET
+# define libc_hidden_builtin_def(X)
+# define libc_hidden_def(X)
+# define libc_hidden_weak(X)
+# define weak_alias(X,Y)
+# undef MEMSET
+# define MEMSET generic_memset
+# include <string/memset.c>
+#endif
index 93ec521..500b7eb 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#define TEST_NAME "bzero"
+#ifdef DO_MEMSET
+# define TEST_NAME "memset"
+#else
+# define TEST_NAME "bzero"
+#endif
 #define MIN_PAGE_SIZE 131072
 #include "bench-string.h"
 
 #include "json-lib.h"
 
+#ifdef DO_MEMSET
+void *generic_memset (void *, int, size_t);
+
+typedef void *(*proto_t) (void *, int, size_t);
+
+IMPL (memset, 1)
+IMPL (generic_memset, 0)
+
+#else
 static void
 memset_zero (void * s, size_t len)
 {
@@ -33,6 +46,7 @@ typedef void (*proto_t) (void *, size_t);
 
 IMPL (bzero, 1)
 IMPL (memset_zero, 0)
+#endif
 
 static void
 do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n)
@@ -43,7 +57,11 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, size_t n)
   TIMING_NOW (start);
   for (i = 0; i < iters; ++i)
     {
+#ifdef DO_MEMSET
+      CALL (impl, s, 0, n);
+#else
       CALL (impl, s, n);
+#endif
     }
   TIMING_NOW (stop);
 
@@ -132,3 +150,13 @@ test_main (void)
 }
 
 #include <support/test-driver.c>
+
+#ifdef DO_MEMSET
+# define libc_hidden_builtin_def(X)
+# define libc_hidden_def(X)
+# define libc_hidden_weak(X)
+# define weak_alias(X,Y)
+# undef MEMSET
+# define MEMSET generic_memset
+# include <string/memset.c>
+#endif
diff --git a/benchtests/bench-memset-zero-large.c b/benchtests/bench-memset-zero-large.c
new file mode 100644 (file)
index 0000000..bc938cd
--- /dev/null
@@ -0,0 +1,20 @@
+/* Measure memset functions for zeroing with large data sizes.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define DO_MEMSET 1
+#include "bench-bzero-large.c"
diff --git a/benchtests/bench-memset-zero-walk.c b/benchtests/bench-memset-zero-walk.c
new file mode 100644 (file)
index 0000000..dce4b43
--- /dev/null
@@ -0,0 +1,20 @@
+/* Measure memset functions for zeroing throughput with large data sizes.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define DO_MEMSET 1
+#include "bench-bzero-walk.c"
diff --git a/benchtests/bench-memset-zero.c b/benchtests/bench-memset-zero.c
new file mode 100644 (file)
index 0000000..535005f
--- /dev/null
@@ -0,0 +1,20 @@
+/* Measure memset functions for zeroing.
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define DO_MEMSET 1
+#include "bench-bzero.c"