mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
clang-format
This commit is contained in:
@@ -1,31 +1,26 @@
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <functional>
|
||||
#include "utils.h"
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
namespace spd = spdlog;
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
const uint64_t g_iterations = 1000000;
|
||||
|
||||
|
||||
std::atomic<size_t> g_counter = {0};
|
||||
|
||||
|
||||
void MeasurePeakDuringLogWrites(const size_t id, std::vector<uint64_t>& result)
|
||||
void MeasurePeakDuringLogWrites(const size_t id, std::vector<uint64_t> &result)
|
||||
{
|
||||
auto logger = spd::get("file_logger");
|
||||
while (true)
|
||||
@@ -44,13 +39,12 @@ void MeasurePeakDuringLogWrites(const size_t id, std::vector<uint64_t>& result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PrintResults(const std::map<size_t, std::vector<uint64_t>>& threads_result, size_t total_us)
|
||||
void PrintResults(const std::map<size_t, std::vector<uint64_t>> &threads_result, size_t total_us)
|
||||
{
|
||||
|
||||
std::vector<uint64_t> all_measurements;
|
||||
all_measurements.reserve(g_iterations);
|
||||
for (auto& t_result : threads_result)
|
||||
for (auto &t_result : threads_result)
|
||||
{
|
||||
all_measurements.insert(all_measurements.end(), t_result.second.begin(), t_result.second.end());
|
||||
}
|
||||
@@ -60,13 +54,12 @@ void PrintResults(const std::map<size_t, std::vector<uint64_t>>& threads_result,
|
||||
|
||||
// calc avg
|
||||
auto total = accumulate(begin(all_measurements), end(all_measurements), 0, std::plus<uint64_t>());
|
||||
auto avg = double(total)/all_measurements.size();
|
||||
|
||||
std::cout << "[spdlog] worst: " << std::setw(10) << std::right << worst << "\tAvg: " << avg << "\tTotal: " << utils::format(total_us) << " us" << std::endl;
|
||||
auto avg = double(total) / all_measurements.size();
|
||||
|
||||
std::cout << "[spdlog] worst: " << std::setw(10) << std::right << worst << "\tAvg: " << avg << "\tTotal: " << utils::format(total_us)
|
||||
<< " us" << std::endl;
|
||||
}
|
||||
}// anonymous
|
||||
|
||||
} // namespace
|
||||
|
||||
// The purpose of this test is NOT to see how fast
|
||||
// each thread can possibly write. It is to see what
|
||||
@@ -76,9 +69,9 @@ void PrintResults(const std::map<size_t, std::vector<uint64_t>>& threads_result,
|
||||
// an atomic counter is used to give each thread what
|
||||
// it is to write next. The overhead of atomic
|
||||
// synchronization between the threads are not counted in the worst case latency
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
size_t number_of_threads {0};
|
||||
size_t number_of_threads{0};
|
||||
if (argc == 2)
|
||||
{
|
||||
number_of_threads = atoi(argv[1]);
|
||||
@@ -89,7 +82,6 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::thread> threads(number_of_threads);
|
||||
std::map<size_t, std::vector<uint64_t>> threads_result;
|
||||
|
||||
@@ -104,8 +96,8 @@ int main(int argc, char** argv)
|
||||
spdlog::set_async_mode(queue_size);
|
||||
auto logger = spdlog::create<spd::sinks::simple_file_sink_mt>("file_logger", "spdlog.log", true);
|
||||
|
||||
//force flush on every call to compare with g3log
|
||||
auto s = (spd::sinks::simple_file_sink_mt*)logger->sinks()[0].get();
|
||||
// force flush on every call to compare with g3log
|
||||
auto s = (spd::sinks::simple_file_sink_mt *)logger->sinks()[0].get();
|
||||
s->set_force_flush(true);
|
||||
|
||||
auto start_time_application_total = std::chrono::high_resolution_clock::now();
|
||||
@@ -119,10 +111,9 @@ int main(int argc, char** argv)
|
||||
}
|
||||
auto stop_time_application_total = std::chrono::high_resolution_clock::now();
|
||||
|
||||
uint64_t total_time_in_us = std::chrono::duration_cast<std::chrono::microseconds>(stop_time_application_total - start_time_application_total).count();
|
||||
uint64_t total_time_in_us =
|
||||
std::chrono::duration_cast<std::chrono::microseconds>(stop_time_application_total - start_time_application_total).count();
|
||||
|
||||
PrintResults(threads_result, total_time_in_us);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user