summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/benchmark/bench_log.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
commit0ece30dc7c0e34b4c5911969b8fa99c33c6d023c (patch)
tree671325d3fec09b999411e4e3ab84ef8259261818 /protocols/Telegram/tdlib/td/benchmark/bench_log.cpp
parent46c53ffc6809c67e4607e99951a2846c382b63b2 (diff)
Telegram: update for TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/benchmark/bench_log.cpp')
-rw-r--r--protocols/Telegram/tdlib/td/benchmark/bench_log.cpp63
1 files changed, 30 insertions, 33 deletions
diff --git a/protocols/Telegram/tdlib/td/benchmark/bench_log.cpp b/protocols/Telegram/tdlib/td/benchmark/bench_log.cpp
index a57b1b9b42..8c2628b8a9 100644
--- a/protocols/Telegram/tdlib/td/benchmark/bench_log.cpp
+++ b/protocols/Telegram/tdlib/td/benchmark/bench_log.cpp
@@ -1,16 +1,16 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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)
//
#include "td/utils/benchmark.h"
+#include "td/utils/common.h"
#include "td/utils/logging.h"
#include <cstdio>
#include <fstream>
#include <iostream>
-#include <mutex>
#include <ostream>
#include <streambuf>
#include <string>
@@ -35,63 +35,63 @@ std::string create_tmp_file() {
#endif
}
-class IostreamWriteBench : public td::Benchmark {
+class IostreamWriteBench final : public td::Benchmark {
protected:
std::string file_name_;
std::ofstream stream;
- enum { buffer_size = 1 << 20 };
- char buffer[buffer_size];
+ static constexpr std::size_t BUFFER_SIZE = 1 << 20;
+ char buffer[BUFFER_SIZE];
public:
- std::string get_description() const override {
+ std::string get_description() const final {
return "ostream (to file, no buf, no flush)";
}
- void start_up() override {
+ void start_up() final {
file_name_ = create_tmp_file();
stream.open(file_name_.c_str());
CHECK(stream.is_open());
- // stream.rdbuf()->pubsetbuf(buffer, buffer_size);
+ // stream.rdbuf()->pubsetbuf(buffer, BUFFER_SIZE);
}
- void run(int n) override {
+ void run(int n) final {
for (int i = 0; i < n; i++) {
stream << "This is just for test" << 987654321 << '\n';
}
}
- void tear_down() override {
+ void tear_down() final {
stream.close();
unlink(file_name_.c_str());
}
};
-class FILEWriteBench : public td::Benchmark {
+class FILEWriteBench final : public td::Benchmark {
protected:
std::string file_name_;
FILE *file;
- enum { buffer_size = 1 << 20 };
- char buffer[buffer_size];
+ static constexpr std::size_t BUFFER_SIZE = 1 << 20;
+ char buffer[BUFFER_SIZE];
public:
- std::string get_description() const override {
+ std::string get_description() const final {
return "std::fprintf (to file, no buf, no flush)";
}
- void start_up() override {
+ void start_up() final {
file_name_ = create_tmp_file();
file = fopen(file_name_.c_str(), "w");
- // setvbuf(file, buffer, _IOFBF, buffer_size);
+ // setvbuf(file, buffer, _IOFBF, BUFFER_SIZE);
}
- void run(int n) override {
+ void run(int n) final {
for (int i = 0; i < n; i++) {
std::fprintf(file, "This is just for test%d\n", 987654321);
// std::fflush(file);
}
}
- void tear_down() override {
+ void tear_down() final {
std::fclose(file);
unlink(file_name_.c_str());
}
@@ -100,58 +100,56 @@ class FILEWriteBench : public td::Benchmark {
#if TD_ANDROID
#include <android/log.h>
#define ALOG(...) __android_log_print(ANDROID_LOG_VERBOSE, "XXX", __VA_ARGS__)
-class ALogWriteBench : public td::Benchmark {
+class ALogWriteBench final : public td::Benchmark {
public:
- std::string get_description() const override {
+ std::string get_description() const final {
return "android_log";
}
- void start_up() override {
+ void start_up() final {
}
- void run(int n) override {
+ void run(int n) final {
for (int i = 0; i < n; i++) {
ALOG("This is just for test%d\n", 987654321);
}
}
- void tear_down() override {
+ void tear_down() final {
}
};
#endif
-class LogWriteBench : public td::Benchmark {
+class LogWriteBench final : public td::Benchmark {
protected:
std::string file_name_;
std::ofstream stream;
std::streambuf *old_buf;
- enum { buffer_size = 1 << 20 };
- char buffer[buffer_size];
+ static constexpr std::size_t BUFFER_SIZE = 1 << 20;
+ char buffer[BUFFER_SIZE];
public:
- std::string get_description() const override {
+ std::string get_description() const final {
return "td_log (slow in debug mode)";
}
- void start_up() override {
+ void start_up() final {
file_name_ = create_tmp_file();
stream.open(file_name_.c_str());
CHECK(stream.is_open());
old_buf = std::cerr.rdbuf(stream.rdbuf());
}
- void run(int n) override {
+ void run(int n) final {
for (int i = 0; i < n; i++) {
LOG(DEBUG) << "This is just for test" << 987654321;
}
}
- void tear_down() override {
+ void tear_down() final {
stream.close();
unlink(file_name_.c_str());
std::cerr.rdbuf(old_buf);
}
};
-std::mutex mutex;
-
int main() {
td::bench(LogWriteBench());
#if TD_ANDROID
@@ -159,5 +157,4 @@ int main() {
#endif
td::bench(IostreamWriteBench());
td::bench(FILEWriteBench());
- return 0;
}