diff mbox series

[v6,10/10] tests/bench: Add bufferiszero-bench

Message ID 20240424225705.929812-11-richard.henderson@linaro.org
State Superseded
Headers show
Series Optimize buffer_is_zero | expand

Commit Message

Richard Henderson April 24, 2024, 10:57 p.m. UTC
Benchmark each acceleration function vs an aligned buffer of zeros.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/bench/bufferiszero-bench.c | 47 ++++++++++++++++++++++++++++++++
 tests/bench/meson.build          |  1 +
 2 files changed, 48 insertions(+)
 create mode 100644 tests/bench/bufferiszero-bench.c

Comments

Philippe Mathieu-Daudé April 29, 2024, 11:12 a.m. UTC | #1
On 25/4/24 00:57, Richard Henderson wrote:
> Benchmark each acceleration function vs an aligned buffer of zeros.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   tests/bench/bufferiszero-bench.c | 47 ++++++++++++++++++++++++++++++++
>   tests/bench/meson.build          |  1 +
>   2 files changed, 48 insertions(+)
>   create mode 100644 tests/bench/bufferiszero-bench.c


> +static void test(const void *opaque)
> +{
> +    size_t max = 64 * KiB;
> +    void *buf = g_malloc0(max);
> +    int accel_index = 0;

Nitpicking, accel_index could be unsigned like in util/bufferiszero.c.

> +
> +    do {
> +        if (accel_index != 0) {
> +            g_test_message("%s", "");  /* gnu_printf Werror for simple "" */
> +        }
> +        for (size_t len = 1 * KiB; len <= max; len *= 4) {
> +            double total = 0.0;
> +
> +            g_test_timer_start();
> +            do {
> +                buffer_is_zero_ge256(buf, len);
> +                total += len;
> +            } while (g_test_timer_elapsed() < 0.5);
> +
> +            total /= MiB;
> +            g_test_message("buffer_is_zero #%d: %2zuKB %8.0f MB/sec",
> +                           accel_index, len / (size_t)KiB,

Thus "buffer_is_zero #%u:..."

Regardless,
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +                           total / g_test_timer_last());
> +        }
> +        accel_index++;
> +    } while (test_buffer_is_zero_next_accel());
> +
> +    g_free(buf);
> +}
diff mbox series

Patch

diff --git a/tests/bench/bufferiszero-bench.c b/tests/bench/bufferiszero-bench.c
new file mode 100644
index 0000000000..222695c1fa
--- /dev/null
+++ b/tests/bench/bufferiszero-bench.c
@@ -0,0 +1,47 @@ 
+/*
+ * QEMU buffer_is_zero speed benchmark
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "qemu/cutils.h"
+#include "qemu/units.h"
+
+static void test(const void *opaque)
+{
+    size_t max = 64 * KiB;
+    void *buf = g_malloc0(max);
+    int accel_index = 0;
+
+    do {
+        if (accel_index != 0) {
+            g_test_message("%s", "");  /* gnu_printf Werror for simple "" */
+        }
+        for (size_t len = 1 * KiB; len <= max; len *= 4) {
+            double total = 0.0;
+
+            g_test_timer_start();
+            do {
+                buffer_is_zero_ge256(buf, len);
+                total += len;
+            } while (g_test_timer_elapsed() < 0.5);
+
+            total /= MiB;
+            g_test_message("buffer_is_zero #%d: %2zuKB %8.0f MB/sec",
+                           accel_index, len / (size_t)KiB,
+                           total / g_test_timer_last());
+        }
+        accel_index++;
+    } while (test_buffer_is_zero_next_accel());
+
+    g_free(buf);
+}
+
+int main(int argc, char **argv)
+{
+    g_test_init(&argc, &argv, NULL);
+    g_test_add_data_func("/cutils/bufferiszero/speed", NULL, test);
+    return g_test_run();
+}
diff --git a/tests/bench/meson.build b/tests/bench/meson.build
index 7e76338a52..4cd7a2f6b5 100644
--- a/tests/bench/meson.build
+++ b/tests/bench/meson.build
@@ -21,6 +21,7 @@  benchs = {}
 
 if have_block
   benchs += {
+     'bufferiszero-bench': [],
      'benchmark-crypto-hash': [crypto],
      'benchmark-crypto-hmac': [crypto],
      'benchmark-crypto-cipher': [crypto],