]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add microbenchmark for isc_iterated_hash()
authorOndřej Surý <ondrej@isc.org>
Mon, 16 Jan 2023 09:54:22 +0000 (10:54 +0100)
committerOndřej Surý <ondrej@isc.org>
Wed, 18 Jan 2023 17:32:57 +0000 (18:32 +0100)
Add microbenchmark for isc_iterated_hash() to measure the speed of NSEC3
per second.

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

index b166d01436a42181a81f80ef65776d73402e7148..afd821b4254b92645967857c4047b4551227ab51 100644 (file)
@@ -1,4 +1,5 @@
 /ascii
 /compress
+/iterated_hash
 /dns_name_fromwire
 /siphash
index c5be25c8ec075b90eb18bc456bb26a165d84565a..f99d47ed571d896db1a5bef23c4b888b80793035 100644 (file)
@@ -12,6 +12,7 @@ LDADD +=                      \
 noinst_PROGRAMS =              \
        ascii                   \
        compress                \
+       iterated_hash           \
        dns_name_fromwire       \
        siphash
 
diff --git a/tests/bench/iterated_hash.c b/tests/bench/iterated_hash.c
new file mode 100644 (file)
index 0000000..a8da177
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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/iterated_hash.h>
+#include <isc/random.h>
+#include <isc/time.h>
+
+#include <dns/name.h>
+
+static void
+time_it(const int count, const int iterations, const unsigned char *salt,
+       const int saltlen, const unsigned char *in, const int inlen) {
+       uint8_t out[NSEC3_MAX_HASH_LENGTH] = { 0 };
+       isc_time_t start, finish;
+
+       printf("%d iterations, %d salt length, %d input length: ", iterations,
+              saltlen, inlen);
+       fflush(stdout);
+
+       isc_time_now_hires(&start);
+
+       int i = 0;
+       while (i++ < count) {
+               isc_iterated_hash(out, 1, iterations, salt, saltlen, in, inlen);
+       }
+
+       isc_time_now_hires(&finish);
+
+       uint64_t microseconds = isc_time_microdiff(&finish, &start);
+       printf("%0.2f us per iterated_hash()\n", (double)microseconds / count);
+       fflush(stdout);
+}
+
+int
+main(void) {
+       uint8_t salt[DNS_NAME_MAXWIRE];
+       uint8_t in[DNS_NAME_MAXWIRE];
+       size_t saltlen = sizeof(salt);
+       size_t inlen = sizeof(in);
+
+       isc_random_buf(salt, saltlen);
+       isc_random_buf(in, inlen);
+
+       time_it(10000, 150, salt, saltlen, in, inlen);
+       time_it(10000, 15, salt, saltlen, in, inlen);
+       time_it(10000, 0, salt, saltlen, in, inlen);
+
+       saltlen = 32;
+       inlen = 32;
+
+       time_it(10000, 150, salt, 32, in, inlen);
+       time_it(10000, 15, salt, 32, in, inlen);
+       time_it(10000, 0, salt, saltlen, in, inlen);
+
+       saltlen = 0;
+       inlen = 1;
+
+       time_it(10000, 150, salt, 32, in, inlen);
+       time_it(10000, 15, salt, 32, in, inlen);
+       time_it(10000, 0, salt, saltlen, in, inlen);
+}