]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add speedtest for burtle and sip
authorOtto <otto.moerbeek@open-xchange.com>
Fri, 22 Oct 2021 10:56:52 +0000 (12:56 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Fri, 22 Oct 2021 10:56:52 +0000 (12:56 +0200)
pdns/speedtest.cc

index f8ca9d5ec33c45659ef765c8dc7dff16b3bcf2c7..0cce35e4660eb44ec12c24e342618114f0df552a 100644 (file)
 #include "dns_random.hh"
 #include "arguments.hh"
 
+#if defined(HAVE_LIBSODIUM)
+#include <sodium.h>
+#endif
+
 #ifndef RECURSOR
 #include "statbag.hh"
 #include "base64.hh"
@@ -1090,6 +1094,51 @@ private:
   const std::string d_password{"test password"};
 };
 
+struct BurtleHashTest
+{
+  explicit BurtleHashTest(const string& str) : d_name(str) {}
+
+  string getName() const
+  {
+    return "BurtleHash";
+  }
+
+  void operator()() const
+  {
+    burtle(reinterpret_cast<const unsigned char*>(d_name.data()), d_name.length(), 0);
+
+  }
+
+private:
+  const string d_name;
+};
+
+
+#if defined(HAVE_LIBSODIUM)
+struct SipHashTest
+{
+  explicit SipHashTest(const string& str) : d_name(str)
+  {
+    crypto_shorthash_keygen(d_key);
+  }
+
+  string getName() const
+  {
+    return "SipHash";
+  }
+
+  void operator()() const
+  {
+    unsigned char out[crypto_shorthash_BYTES];
+    crypto_shorthash(out, reinterpret_cast<const unsigned char*>(d_name.data()), d_name.length(), d_key);
+  }
+
+private:
+  const string d_name;
+  unsigned char d_key[crypto_shorthash_KEYBYTES];
+};
+#endif
+
 int main(int argc, char** argv)
 try
 {
@@ -1237,6 +1286,9 @@ try
   doRun(StatRingDNSNameQTypeTest(DNSName("example.com"), QType(1)));
 #endif
 
+  doRun(BurtleHashTest("a string of chars"));
+  doRun(SipHashTest("a string of chars"));
+
   cerr<<"Total runs: " << g_totalRuns<<endl;
 
 }