Skip to content

Commit 1de6a90

Browse files
committed
Add speedtest for shuffle, plus a speedup in shuffle itself
1 parent 8089aeb commit 1de6a90

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

pdns/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ speedtest_SOURCES = \
964964
qtype.cc \
965965
rcpgenerator.cc rcpgenerator.hh \
966966
sillyrecords.cc \
967+
shuffle.cc shuffle.hh \
967968
speedtest.cc \
968969
statbag.cc \
969970
svc-records.cc svc-records.hh \

pdns/shuffle.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ unsigned int pdns::dedup(vector<DNSRecord>& rrs)
158158
unsigned int numDups = 0;
159159

160160
for (const auto& rec : rrs) {
161-
const auto key = rec.getContent()->wireFormatContent(rec.d_name, true, true);
161+
auto key = rec.getContent()->wireFormatContent(rec.d_name, true, true);
162162
// This ignores class, ttl and place by using constants for those
163-
if (!seen.emplace(key).second) {
163+
if (!seen.emplace(std::move(key)).second) {
164164
dups[counter] = true;
165165
numDups++;
166166
}

pdns/speedtest.cc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "lock.hh"
1515
#include "dns_random.hh"
1616
#include "arguments.hh"
17+
#include "shuffle.hh"
1718

1819
#if defined(HAVE_LIBSODIUM)
1920
#include <sodium.h>
@@ -1181,6 +1182,37 @@ struct SipHashTest
11811182
};
11821183
#endif
11831184

1185+
struct DedupRecordsTest
1186+
{
1187+
explicit DedupRecordsTest(size_t howmany, bool dedup) : d_howmany(howmany), d_dedup(dedup)
1188+
{
1189+
}
1190+
1191+
[[nodiscard]] string getName() const
1192+
{
1193+
return "DedupRecords " + std::to_string(d_howmany) + std::string(d_dedup ? "": " (generate only)");
1194+
}
1195+
1196+
void operator()() const
1197+
{
1198+
std::vector<DNSRecord> vec;
1199+
vec.reserve(d_howmany);
1200+
std::string name("some.name.in.some.domain");
1201+
for (size_t i = 0; i < d_howmany; i++) {
1202+
auto content = DNSRecordContent::make(QType::TXT, QClass::IN, "\"a text " + std::to_string(i) + "\"");
1203+
DNSRecord rec(name, content, QType::TXT);
1204+
vec.emplace_back(std::move(rec));
1205+
}
1206+
if (d_dedup) {
1207+
pdns::dedup(vec);
1208+
}
1209+
}
1210+
1211+
private:
1212+
size_t d_howmany;
1213+
bool d_dedup;
1214+
};
1215+
11841216
int main()
11851217
{
11861218
try {
@@ -1335,6 +1367,12 @@ int main()
13351367
#ifdef HAVE_LIBSODIUM
13361368
doRun(SipHashTest("a string of chars"));
13371369
#endif
1370+
doRun(DedupRecordsTest(2, false));
1371+
doRun(DedupRecordsTest(2, true));
1372+
doRun(DedupRecordsTest(256, false));
1373+
doRun(DedupRecordsTest(256, true));
1374+
doRun(DedupRecordsTest(4096, false));
1375+
doRun(DedupRecordsTest(4096, true));
13381376

13391377
cerr<<"Total runs: " << g_totalRuns<<endl;
13401378
}

0 commit comments

Comments
 (0)