]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
A simple siphash benchmark
authorTony Finch <fanf@isc.org>
Wed, 21 Sep 2022 12:38:08 +0000 (13:38 +0100)
committerOndřej Surý <ondrej@isc.org>
Tue, 4 Oct 2022 08:32:40 +0000 (10:32 +0200)
To see the effect of adding a case-insentitive option.

tests/bench/.gitignore
tests/bench/Makefile.am
tests/bench/siphash.c [new file with mode: 0644]

index c9c3825ad183e4b4bfac3b54f51fedf3538a136a..fb6b5a462aff36b2c064282ef472c47d9fca3716 100644 (file)
@@ -1 +1,2 @@
 ascii
+siphash
index 171db37b39032758cc6a164e296c1c103330cb33..c53e6ea51d59e913a6a37a7f5c6d9c3eaa8c294d 100644 (file)
@@ -7,4 +7,5 @@ LDADD +=                        \
        $(LIBISC_LIBS)
 
 noinst_PROGRAMS =              \
-       ascii
+       ascii                   \
+       siphash
diff --git a/tests/bench/siphash.c b/tests/bench/siphash.c
new file mode 100644 (file)
index 0000000..c696da2
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, you can obtain one at https://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <isc/ascii.h>
+#include <isc/random.h>
+#include <isc/siphash.h>
+#include <isc/time.h>
+
+#define SIZE (1024 * 1024)
+
+int
+main(void) {
+       static uint8_t bytes[SIZE];
+       static uint8_t key[16];
+
+       isc_random_buf(bytes, SIZE);
+       isc_random_buf(key, sizeof(key));
+
+       for (size_t len = 256; len > 0; len = len * 4 / 5) {
+               isc_time_t start;
+               isc_time_now_hires(&start);
+
+               uint64_t count = 0;
+               uint64_t sum = 0;
+               for (size_t end = len; end < SIZE; end += len) {
+                       uint64_t hash;
+                       uint8_t lower[1024];
+                       isc_ascii_lowercopy(lower, bytes + end - len, len);
+                       isc_siphash24(key, lower, len, (void *)&hash);
+                       sum += hash;
+                       count++;
+               }
+
+               isc_time_t finish;
+               isc_time_now_hires(&finish);
+
+               uint64_t us = isc_time_microdiff(&finish, &start);
+               printf("%f us wide-lower len %3zu, %7llu kh/s (%llx)\n",
+                      (double)us / 1000000.0, len,
+                      (unsigned long long)(count * 1000 / us),
+                      (unsigned long long)sum);
+       }
+
+       for (size_t len = 256; len > 0; len = len * 4 / 5) {
+               isc_time_t start;
+               isc_time_now_hires(&start);
+
+               uint64_t count = 0;
+               uint64_t sum = 0;
+               for (size_t end = len; end < SIZE; end += len) {
+                       uint64_t hash;
+                       isc_siphash24(key, bytes + end - len, len,
+                                     (void *)&hash);
+                       sum += hash;
+                       count++;
+               }
+
+               isc_time_t finish;
+               isc_time_now_hires(&finish);
+
+               uint64_t us = isc_time_microdiff(&finish, &start);
+               printf("%f us wide-bytes len %3zu, %7llu kh/s (%llx)\n",
+                      (double)us / 1000000.0, len,
+                      (unsigned long long)(count * 1000 / us),
+                      (unsigned long long)sum);
+       }
+
+       for (size_t len = 256; len > 0; len = len * 4 / 5) {
+               isc_time_t start;
+               isc_time_now_hires(&start);
+
+               uint64_t count = 0;
+               uint32_t sum = 0;
+               for (size_t end = len; end < SIZE; end += len) {
+                       uint32_t hash;
+                       uint8_t lower[1024];
+                       isc_ascii_lowercopy(lower, bytes + end - len, len);
+                       isc_halfsiphash24(key, lower, len, (void *)&hash);
+                       sum += hash;
+                       count++;
+               }
+
+               isc_time_t finish;
+               isc_time_now_hires(&finish);
+
+               uint64_t us = isc_time_microdiff(&finish, &start);
+               printf("%f us half-lower len %3zu, %7llu kh/s (%llx)\n",
+                      (double)us / 1000000.0, len,
+                      (unsigned long long)(count * 1000 / us),
+                      (unsigned long long)sum);
+       }
+
+       for (size_t len = 256; len > 0; len = len * 4 / 5) {
+               isc_time_t start;
+               isc_time_now_hires(&start);
+
+               uint64_t count = 0;
+               uint32_t sum = 0;
+               for (size_t end = len; end < SIZE; end += len) {
+                       uint32_t hash;
+                       isc_halfsiphash24(key, bytes + end - len, len,
+                                         (void *)&hash);
+                       sum += hash;
+                       count++;
+               }
+
+               isc_time_t finish;
+               isc_time_now_hires(&finish);
+
+               uint64_t us = isc_time_microdiff(&finish, &start);
+               printf("%f us half-bytes len %3zu, %7llu kh/s (%llx)\n",
+                      (double)us / 1000000.0, len,
+                      (unsigned long long)(count * 1000 / us),
+                      (unsigned long long)sum);
+       }
+}