Commit 779328a9 authored by gabime's avatar gabime

Fixed async_bench

parent 01e05a44
...@@ -103,19 +103,28 @@ int main(int argc, char *argv[]) ...@@ -103,19 +103,28 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count) void thread_fun(std::shared_ptr<spdlog::logger> logger, int howmany)
{
for (int i = 0; i < howmany; i++)
{
logger->info("Hello logger: msg number {}", i);
}
}
void bench_mt(int howmany, std::shared_ptr<spdlog::logger> logger, int thread_count)
{ {
using std::chrono::high_resolution_clock; using std::chrono::high_resolution_clock;
vector<thread> threads; vector<thread> threads;
auto start = high_resolution_clock::now(); auto start = high_resolution_clock::now();
int msgs_per_thread = howmany / thread_count;
int msgs_per_thread_mod = howmany % thread_count;
for (int t = 0; t < thread_count; ++t) for (int t = 0; t < thread_count; ++t)
{ {
threads.push_back(std::thread([&]() { if (t == 0 && msgs_per_thread_mod)
for (int j = 0; j < howmany / thread_count; j++) threads.push_back(std::thread(thread_fun, logger, msgs_per_thread + msgs_per_thread_mod));
{ else
log->info("Hello logger: msg number {}", j); threads.push_back(std::thread(thread_fun, logger, msgs_per_thread));
}
}));
} }
for (auto &t : threads) for (auto &t : threads)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment