2018-03-06 14:25:36 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2018-03-06 14:25:36 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
2023-05-10 13:35:21 +02:00
|
|
|
#include "td/utils/benchmark.h"
|
2023-05-18 13:33:00 +02:00
|
|
|
#include "td/utils/common.h"
|
2018-03-06 14:25:36 +01:00
|
|
|
#include "td/utils/Enumerator.h"
|
2023-05-10 13:35:21 +02:00
|
|
|
#include "td/utils/Random.h"
|
2018-03-06 14:25:36 +01:00
|
|
|
#include "td/utils/tests.h"
|
|
|
|
|
|
|
|
TEST(Enumerator, simple) {
|
2023-05-18 13:33:00 +02:00
|
|
|
td::Enumerator<td::string> e;
|
2018-03-06 14:25:36 +01:00
|
|
|
auto b = e.add("b");
|
|
|
|
auto a = e.add("a");
|
|
|
|
auto d = e.add("d");
|
|
|
|
auto c = e.add("c");
|
|
|
|
ASSERT_STREQ(e.get(a), "a");
|
|
|
|
ASSERT_STREQ(e.get(b), "b");
|
|
|
|
ASSERT_STREQ(e.get(c), "c");
|
|
|
|
ASSERT_STREQ(e.get(d), "d");
|
|
|
|
ASSERT_EQ(a, e.add("a"));
|
|
|
|
ASSERT_EQ(b, e.add("b"));
|
|
|
|
ASSERT_EQ(c, e.add("c"));
|
|
|
|
ASSERT_EQ(d, e.add("d"));
|
|
|
|
}
|
2023-05-10 13:35:21 +02:00
|
|
|
|
|
|
|
TEST(Enumerator, add_benchmark) {
|
|
|
|
class EnumeratorAddBenchmark final : public td::Benchmark {
|
|
|
|
public:
|
|
|
|
td::string get_description() const final {
|
|
|
|
return "EnumeratorAdd";
|
|
|
|
}
|
|
|
|
|
|
|
|
void run(int n) final {
|
|
|
|
td::Enumerator<int> enumerator;
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
enumerator.add(td::Random::fast(1, 10000000));
|
|
|
|
}
|
|
|
|
td::do_not_optimize_away(enumerator.size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
bench(EnumeratorAddBenchmark());
|
|
|
|
}
|