Skip to content

Commit

Permalink
Add speedtest for shuffle, plus a speedup in shuffle itself
Browse files Browse the repository at this point in the history
  • Loading branch information
omoerbeek committed Oct 25, 2024
1 parent 8089aeb commit 1de6a90
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions pdns/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,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 \
Expand Down
4 changes: 2 additions & 2 deletions pdns/shuffle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ unsigned int pdns::dedup(vector<DNSRecord>& rrs)
unsigned int numDups = 0;

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++;
}
Expand Down
38 changes: 38 additions & 0 deletions pdns/speedtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "lock.hh"
#include "dns_random.hh"
#include "arguments.hh"
#include "shuffle.hh"

#if defined(HAVE_LIBSODIUM)
#include <sodium.h>
Expand Down Expand Up @@ -1181,6 +1182,37 @@ struct SipHashTest
};
#endif

struct DedupRecordsTest
{
explicit DedupRecordsTest(size_t howmany, bool dedup) : d_howmany(howmany), d_dedup(dedup)
{
}

[[nodiscard]] string getName() const
{
return "DedupRecords " + std::to_string(d_howmany) + std::string(d_dedup ? "": " (generate only)");
}

void operator()() const
{
std::vector<DNSRecord> vec;
vec.reserve(d_howmany);
std::string name("some.name.in.some.domain");
for (size_t i = 0; i < d_howmany; i++) {
auto content = DNSRecordContent::make(QType::TXT, QClass::IN, "\"a text " + std::to_string(i) + "\"");
DNSRecord rec(name, content, QType::TXT);
vec.emplace_back(std::move(rec));
}
if (d_dedup) {
pdns::dedup(vec);
}
}

private:
size_t d_howmany;
bool d_dedup;
};

int main()

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 164 lines.
{
try {
Expand Down Expand Up @@ -1335,6 +1367,12 @@ int main()
#ifdef HAVE_LIBSODIUM
doRun(SipHashTest("a string of chars"));
#endif
doRun(DedupRecordsTest(2, false));
doRun(DedupRecordsTest(2, true));
doRun(DedupRecordsTest(256, false));
doRun(DedupRecordsTest(256, true));
doRun(DedupRecordsTest(4096, false));
doRun(DedupRecordsTest(4096, true));

cerr<<"Total runs: " << g_totalRuns<<endl;
}
Expand Down

0 comments on commit 1de6a90

Please sign in to comment.