]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add speedtest for shuffle, plus a speedup in shuffle itself
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 25 Oct 2024 08:04:36 +0000 (10:04 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Mon, 16 Dec 2024 10:28:53 +0000 (11:28 +0100)
pdns/Makefile.am
pdns/shuffle.cc
pdns/speedtest.cc

index 042ad78769b56d66fc92bc9464e406d58d46b4c8..dcdfada5491a3bae3439ad08a189a5489aee61a9 100644 (file)
@@ -950,6 +950,7 @@ speedtest_SOURCES = \
        qtype.cc \
        rcpgenerator.cc rcpgenerator.hh \
        sillyrecords.cc \
+       shuffle.cc shuffle.hh \
        speedtest.cc \
        statbag.cc \
        svc-records.cc svc-records.hh \
index 1fbc004cf920a82656b59d70d7624a928c076a4f..15eee7b6f4ec64a8504a83d1aaaa4c5d8847e902 100644 (file)
@@ -157,10 +157,11 @@ unsigned int pdns::dedup(vector<DNSRecord>& rrs)
   unsigned int counter = 0;
   unsigned int numDups = 0;
 
+  seen.reserve(rrs.size());
   for (const auto& rec : rrs) {
-    const auto key = rec.getContent()->wireFormatContent(rec.d_name, true, true);
+    auto key = rec.getContent()->wireFormatContent(rec.d_name, true, true);
     // This ignores class, ttl and place by using constants for those
-    if (!seen.emplace(key).second) {
+    if (!seen.emplace(std::move(key)).second) {
       dups[counter] = true;
       numDups++;
     }
index 976275c3a1a1ce56d434189e5b772cba23e309d9..2c77337bc72dcf93a028868ce6c7ad853362d6d5 100644 (file)
@@ -14,6 +14,7 @@
 #include "lock.hh"
 #include "dns_random.hh"
 #include "arguments.hh"
+#include "shuffle.hh"
 
 #if defined(HAVE_LIBSODIUM)
 #include <sodium.h>
@@ -1181,6 +1182,47 @@ private:
 };
 #endif
 
+struct DedupRecordsTest
+{
+  explicit DedupRecordsTest(size_t howmany, bool dedup, bool withdup = false) : d_howmany(howmany), d_dedup(dedup), d_withdup(withdup)
+  {
+  }
+
+  [[nodiscard]] string getName() const
+  {
+    return std::to_string(d_howmany) + " DedupRecords" + std::string(d_dedup ? "" : " (generate only)") +
+      std::string(d_withdup ? " (with dup)" : "");
+  }
+
+  void operator()() const
+  {
+    std::vector<DNSRecord> vec;
+    vec.reserve(d_howmany);
+    std::string name("some.name.in.some.domain");
+    auto count = d_howmany;
+    if (d_withdup) {
+      count--;
+    }
+    for (size_t i = 0; i < count; i++) {
+      auto content = DNSRecordContent::make(QType::TXT, QClass::IN, "\"a text " + std::to_string(i) + "\"");
+      DNSRecord rec(name, content, QType::TXT);
+      if (i == 0 && d_withdup) {
+        vec.emplace_back(rec);
+      }
+      vec.emplace_back(std::move(rec));
+    }
+
+    if (d_dedup) {
+      pdns::dedup(vec);
+    }
+  }
+
+private:
+  size_t d_howmany;
+  bool d_dedup;
+  bool d_withdup;
+};
+
 int main()
 {
   try {
@@ -1335,6 +1377,15 @@ int main()
 #ifdef HAVE_LIBSODIUM
     doRun(SipHashTest("a string of chars"));
 #endif
+    doRun(DedupRecordsTest(2, false));
+    doRun(DedupRecordsTest(2, true));
+    doRun(DedupRecordsTest(2, true, true));
+    doRun(DedupRecordsTest(256, false));
+    doRun(DedupRecordsTest(256, true));
+    doRun(DedupRecordsTest(256, true, true));
+    doRun(DedupRecordsTest(4096, false));
+    doRun(DedupRecordsTest(4096, true));
+    doRun(DedupRecordsTest(4096, true, true));
 
     cerr<<"Total runs: " << g_totalRuns<<endl;
   }