From 18ed04b990e552b53900d90b56f1b67848c388ed Mon Sep 17 00:00:00 2001 From: gabime Date: Thu, 9 Apr 2020 16:12:52 +0300 Subject: [PATCH] Fixed clang-tidy warnings in bench.cpp --- bench/bench.cpp | 56 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/bench/bench.cpp b/bench/bench.cpp index 591057bd..39334323 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -19,19 +19,15 @@ #include #include -using namespace std; -using namespace std::chrono; -using namespace spdlog; -using namespace spdlog::sinks; -using namespace utils; - void bench(int howmany, std::shared_ptr log); void bench_mt(int howmany, std::shared_ptr log, int thread_count); -void bench_default_api(int howmany, std::shared_ptr log); -void bench_c_string(int howmany, std::shared_ptr log); -static size_t file_size = 30 * 1024 * 1024; -static size_t rotating_files = 5; +// void bench_default_api(int howmany, std::shared_ptr log); +// void bench_c_string(int howmany, std::shared_ptr log); + +static const size_t file_size = 30 * 1024 * 1024; +static const size_t rotating_files = 5; +static const int max_threads = 1000; void bench_threaded_logging(int threads, int iters) { @@ -116,9 +112,18 @@ int main(int argc, char *argv[]) { if (argc > 1) - iters = atoi(argv[1]); + { + iters = std::stoi(argv[1]); + } if (argc > 2) - threads = atoi(argv[2]); + { + threads = std::stoi(argv[2]); + } + + if(threads > max_threads) + { + throw std::runtime_error(fmt::format("Number of threads exceeds maximum({}})", max_threads)); + } bench_single_threaded(iters); bench_threaded_logging(1, iters); @@ -135,6 +140,9 @@ int main(int argc, char *argv[]) void bench(int howmany, std::shared_ptr log) { using std::chrono::high_resolution_clock; + using std::chrono::duration; + using std::chrono::duration_cast; + auto start = high_resolution_clock::now(); for (auto i = 0; i < howmany; ++i) { @@ -151,16 +159,20 @@ void bench(int howmany, std::shared_ptr log) void bench_mt(int howmany, std::shared_ptr log, int thread_count) { using std::chrono::high_resolution_clock; - vector threads; + using std::chrono::duration; + using std::chrono::duration_cast; + + std::vector threads; + threads.reserve(thread_count); auto start = high_resolution_clock::now(); for (int t = 0; t < thread_count; ++t) { - threads.push_back(std::thread([&]() { + threads.emplace_back([&]() { for (int j = 0; j < howmany / thread_count; j++) { log->info("Hello logger: msg number {}", j); } - })); + }); } for (auto &t : threads) @@ -174,9 +186,13 @@ void bench_mt(int howmany, std::shared_ptr log, int thread_count spdlog::drop(log->name()); } +/* void bench_default_api(int howmany, std::shared_ptr log) { using std::chrono::high_resolution_clock; + using std::chrono::duration; + using std::chrono::duration_cast; + auto orig_default = spdlog::default_logger(); spdlog::set_default_logger(log); auto start = high_resolution_clock::now(); @@ -194,18 +210,22 @@ void bench_default_api(int howmany, std::shared_ptr log) void bench_c_string(int howmany, std::shared_ptr log) { + using std::chrono::high_resolution_clock; + using std::chrono::duration; + using std::chrono::duration_cast; + const char *msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pharetra metus cursus " "lacus placerat congue. Nulla egestas, mauris a tincidunt tempus, enim lectus volutpat mi, eu consequat sem " "libero nec massa. In dapibus ipsum a diam rhoncus gravida. Etiam non dapibus eros. Donec fringilla dui sed " "augue pretium, nec scelerisque est maximus. Nullam convallis, sem nec blandit maximus, nisi turpis ornare " "nisl, sit amet volutpat neque massa eu odio. Maecenas malesuada quam ex, posuere congue nibh turpis duis."; - using std::chrono::high_resolution_clock; + auto orig_default = spdlog::default_logger(); spdlog::set_default_logger(log); auto start = high_resolution_clock::now(); for (auto i = 0; i < howmany; ++i) { - spdlog::log(level::info, msg); + spdlog::log(spdlog::level::info, msg); } auto delta = high_resolution_clock::now() - start; @@ -214,3 +234,5 @@ void bench_c_string(int howmany, std::shared_ptr log) spdlog::set_default_logger(std::move(orig_default)); spdlog::info("{:<30} Elapsed: {:0.2f} secs {:>16n}/sec", log->name(), delta_d, int(howmany / delta_d)); } + +*/ \ No newline at end of file