1 /*
2  * QEMU buffer_is_zero speed benchmark
3  *
4  * This work is licensed under the terms of the GNU GPL, version 2 or
5  * (at your option) any later version.  See the COPYING file in the
6  * top-level directory.
7  */
8 #include "qemu/osdep.h"
9 #include "qemu/cutils.h"
10 #include "qemu/units.h"
11 
12 static void test(const void *opaque)
13 {
14     size_t max = 64 * KiB;
15     void *buf = g_malloc0(max);
16     int accel_index = 0;
17 
18     do {
19         if (accel_index != 0) {
20             g_test_message("%s", "");  /* gnu_printf Werror for simple "" */
21         }
22         for (size_t len = 1 * KiB; len <= max; len *= 4) {
23             double total = 0.0;
24 
25             g_test_timer_start();
26             do {
27                 buffer_is_zero_ge256(buf, len);
28                 total += len;
29             } while (g_test_timer_elapsed() < 0.5);
30 
31             total /= MiB;
32             g_test_message("buffer_is_zero #%d: %2zuKB %8.0f MB/sec",
33                            accel_index, len / (size_t)KiB,
34                            total / g_test_timer_last());
35         }
36         accel_index++;
37     } while (test_buffer_is_zero_next_accel());
38 
39     g_free(buf);
40 }
41 
42 int main(int argc, char **argv)
43 {
44     g_test_init(&argc, &argv, NULL);
45     g_test_add_data_func("/cutils/bufferiszero/speed", NULL, test);
46     return g_test_run();
47 }
48