aboutsummaryrefslogtreecommitdiffhomepage
path: root/benchmark/bench_misc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/bench_misc.cpp')
-rw-r--r--benchmark/bench_misc.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/benchmark/bench_misc.cpp b/benchmark/bench_misc.cpp
index 1242648b8..0d688e1b6 100644
--- a/benchmark/bench_misc.cpp
+++ b/benchmark/bench_misc.cpp
@@ -8,6 +8,7 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/telegram_api.hpp"
+#include "td/utils/algorithm.h"
#include "td/utils/benchmark.h"
#include "td/utils/common.h"
#include "td/utils/logging.h"
@@ -18,6 +19,7 @@
#include "td/utils/port/RwMutex.h"
#include "td/utils/port/Stat.h"
#include "td/utils/port/thread.h"
+#include "td/utils/Random.h"
#include "td/utils/Slice.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"
@@ -676,9 +678,40 @@ class DuplicateCheckerBenchEvenOdd final : public td::Benchmark {
}
};
+BENCH(AddToTopStd, "add_to_top std") {
+ td::vector<int> v;
+ for (int i = 0; i < n; i++) {
+ for (size_t j = 0; j < 10; j++) {
+ auto value = td::Random::fast(0, 9);
+ auto it = std::find(v.begin(), v.end(), value);
+ if (it == v.end()) {
+ if (v.size() == 8) {
+ v.back() = value;
+ } else {
+ v.push_back(value);
+ }
+ it = v.end() - 1;
+ }
+ std::rotate(v.begin(), it, it + 1);
+ }
+ }
+}
+
+BENCH(AddToTopTd, "add_to_top td") {
+ td::vector<int> v;
+ for (int i = 0; i < n; i++) {
+ for (size_t j = 0; j < 10; j++) {
+ td::add_to_top(v, 8, td::Random::fast(0, 9));
+ }
+ }
+}
+
int main() {
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(DEBUG));
+ td::bench(AddToTopStdBench());
+ td::bench(AddToTopTdBench());
+
td::bench(TlToStringUpdateFileBench());
td::bench(TlToStringMessageBench());