Add DuplicateChecker benchmark with repeated message_id.

This commit is contained in:
levlam 2021-08-22 10:25:11 +03:00
parent e0f80ca008
commit f9b71104d4

View File

@ -450,7 +450,7 @@ class MessageIdDuplicateCheckerOld {
std::set<td::int64> saved_message_ids_; std::set<td::int64> saved_message_ids_;
}; };
template<size_t MAX_SAVED_MESSAGE_IDS> template <size_t MAX_SAVED_MESSAGE_IDS>
class MessageIdDuplicateCheckerNew { class MessageIdDuplicateCheckerNew {
public: public:
static td::string get_description() { static td::string get_description() {
@ -544,13 +544,39 @@ class DuplicateCheckerBench final : public td::Benchmark {
} }
}; };
template <class T>
class DuplicateCheckerBenchRepeat final : public td::Benchmark {
td::string get_description() const final {
return PSTRING() << "DuplicateCheckerBenchRepeat" << T::get_description();
}
void run(int n) final {
T checker_;
for (int i = 0; i < n; i++) {
auto iter = i >> 10;
auto pos = i - (iter << 10);
if (pos < 768) {
checker_.check(iter * 768 + pos).ensure();
} else {
checker_.check(iter * 768 + pos - 256).ensure_error();
}
}
}
};
int main() { int main() {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(DEBUG)); SET_VERBOSITY_LEVEL(VERBOSITY_NAME(DEBUG));
td::bench(DuplicateCheckerBenchRepeat<MessageIdDuplicateCheckerOld>());
td::bench(DuplicateCheckerBenchRepeat<MessageIdDuplicateCheckerNew<1000>>());
td::bench(DuplicateCheckerBenchRepeat<MessageIdDuplicateCheckerNewOther>());
td::bench(DuplicateCheckerBenchRepeat<MessageIdDuplicateCheckerNewSimple>());
td::bench(DuplicateCheckerBenchRepeat<MessageIdDuplicateCheckerNew<300>>());
td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerOld>()); td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerOld>());
td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNew<1000>>()); td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNew<1000>>());
td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNewOther>()); td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNewOther>());
td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNewSimple>()); td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNewSimple>());
td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNew<300>>());
td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNew<100>>()); td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNew<100>>());
td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNew<10>>()); td::bench(DuplicateCheckerBench<MessageIdDuplicateCheckerNew<10>>());