mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 01:29:35 +08:00
clang-format
This commit is contained in:
@@ -3,18 +3,18 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
#include <boost/log/core.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/log/expressions.hpp>
|
||||
#include <boost/log/sinks/text_file_backend.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/sources/severity_logger.hpp>
|
||||
#include <boost/log/sources/record_ostream.hpp>
|
||||
#include <boost/log/sources/severity_logger.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
|
||||
namespace logging = boost::log;
|
||||
namespace src = boost::log::sources;
|
||||
@@ -23,62 +23,49 @@ namespace keywords = boost::log::keywords;
|
||||
|
||||
void init()
|
||||
{
|
||||
logging::add_file_log
|
||||
(
|
||||
keywords::file_name = "logs/boost-sample_%N.log", /*< file name pattern >*/
|
||||
keywords::auto_flush = false,
|
||||
keywords::format = "[%TimeStamp%]: %Message%"
|
||||
);
|
||||
logging::add_file_log(keywords::file_name = "logs/boost-sample_%N.log", /*< file name pattern >*/
|
||||
keywords::auto_flush = false, keywords::format = "[%TimeStamp%]: %Message%");
|
||||
|
||||
logging::core::get()->set_filter
|
||||
(
|
||||
logging::trivial::severity >= logging::trivial::info
|
||||
);
|
||||
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
|
||||
}
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int thread_count = 10;
|
||||
if(argc > 1)
|
||||
if (argc > 1)
|
||||
thread_count = atoi(argv[1]);
|
||||
|
||||
int howmany = 1000000;
|
||||
|
||||
|
||||
init();
|
||||
logging::add_common_attributes();
|
||||
|
||||
|
||||
using namespace logging::trivial;
|
||||
|
||||
src::severity_logger_mt< severity_level > lg;
|
||||
src::severity_logger_mt<severity_level> lg;
|
||||
|
||||
std::atomic<int > msg_counter {0};
|
||||
std::atomic<int> msg_counter{0};
|
||||
vector<thread> threads;
|
||||
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]()
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
while (true)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany) break;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
BOOST_LOG_SEV(lg, info) << "boost message #" << counter << ": This is some text for your pleasure";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -3,13 +3,13 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
#include <boost/log/core.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/log/expressions.hpp>
|
||||
#include <boost/log/sinks/text_file_backend.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/sources/severity_logger.hpp>
|
||||
#include <boost/log/sources/record_ostream.hpp>
|
||||
#include <boost/log/sources/severity_logger.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
|
||||
namespace logging = boost::log;
|
||||
namespace src = boost::log::sources;
|
||||
@@ -18,29 +18,21 @@ namespace keywords = boost::log::keywords;
|
||||
|
||||
void init()
|
||||
{
|
||||
logging::add_file_log
|
||||
(
|
||||
keywords::file_name = "logs/boost-sample_%N.log", /*< file name pattern >*/
|
||||
keywords::auto_flush = false,
|
||||
keywords::format = "[%TimeStamp%]: %Message%"
|
||||
);
|
||||
logging::add_file_log(keywords::file_name = "logs/boost-sample_%N.log", /*< file name pattern >*/
|
||||
keywords::auto_flush = false, keywords::format = "[%TimeStamp%]: %Message%");
|
||||
|
||||
logging::core::get()->set_filter
|
||||
(
|
||||
logging::trivial::severity >= logging::trivial::info
|
||||
);
|
||||
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* [])
|
||||
int main(int argc, char *[])
|
||||
{
|
||||
int howmany = 1000000;
|
||||
init();
|
||||
logging::add_common_attributes();
|
||||
|
||||
using namespace logging::trivial;
|
||||
src::severity_logger_mt< severity_level > lg;
|
||||
for(int i = 0 ; i < howmany; ++i)
|
||||
src::severity_logger_mt<severity_level> lg;
|
||||
for (int i = 0; i < howmany; ++i)
|
||||
BOOST_LOG_SEV(lg, info) << "boost message #" << i << ": This is some text for your pleasure";
|
||||
|
||||
return 0;
|
||||
|
@@ -3,9 +3,9 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
#define _ELPP_THREAD_SAFE
|
||||
#include "easylogging++.h"
|
||||
@@ -13,11 +13,11 @@ _INITIALIZE_EASYLOGGINGPP
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int thread_count = 10;
|
||||
if(argc > 1)
|
||||
if (argc > 1)
|
||||
thread_count = atoi(argv[1]);
|
||||
|
||||
int howmany = 1000000;
|
||||
@@ -26,24 +26,23 @@ int main(int argc, char* argv[])
|
||||
el::Configurations conf("easyl.conf");
|
||||
el::Loggers::reconfigureLogger("default", conf);
|
||||
|
||||
std::atomic<int > msg_counter {0};
|
||||
std::atomic<int> msg_counter{0};
|
||||
vector<thread> threads;
|
||||
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]()
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
while (true)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany) break;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
LOG(INFO) << "easylog message #" << counter << ": This is some text for your pleasure";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
@@ -3,12 +3,11 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
|
||||
#include "easylogging++.h"
|
||||
|
||||
_INITIALIZE_EASYLOGGINGPP
|
||||
|
||||
int main(int, char* [])
|
||||
int main(int, char *[])
|
||||
{
|
||||
int howmany = 1000000;
|
||||
|
||||
@@ -16,7 +15,7 @@ int main(int, char* [])
|
||||
el::Configurations conf("easyl.conf");
|
||||
el::Loggers::reconfigureLogger("default", conf);
|
||||
|
||||
for(int i = 0 ; i < howmany; ++i)
|
||||
for (int i = 0; i < howmany; ++i)
|
||||
LOG(INFO) << "easylog message #" << i << ": This is some text for your pleasure";
|
||||
return 0;
|
||||
}
|
||||
|
@@ -3,57 +3,55 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
#include "g2logworker.h"
|
||||
#include "g2log.h"
|
||||
#include "g2logworker.h"
|
||||
|
||||
using namespace std;
|
||||
template<typename T> std::string format(const T& value);
|
||||
template <typename T> std::string format(const T &value);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using clock=steady_clock;
|
||||
using clock = steady_clock;
|
||||
int thread_count = 10;
|
||||
|
||||
if(argc > 1)
|
||||
if (argc > 1)
|
||||
thread_count = atoi(argv[1]);
|
||||
int howmany = 1000000;
|
||||
|
||||
g2LogWorker g2log(argv[0], "logs");
|
||||
g2::initializeLogging(&g2log);
|
||||
|
||||
|
||||
std::atomic<int > msg_counter {0};
|
||||
std::atomic<int> msg_counter{0};
|
||||
vector<thread> threads;
|
||||
auto start = clock::now();
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]()
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
while (true)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany) break;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
LOG(INFO) << "g2log message #" << counter << ": This is some text for your pleasure";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
duration<float> delta = clock::now() - start;
|
||||
float deltaf = delta.count();
|
||||
auto rate = howmany/deltaf;
|
||||
auto rate = howmany / deltaf;
|
||||
|
||||
cout << "Total: " << howmany << std::endl;
|
||||
cout << "Threads: " << thread_count << std::endl;
|
||||
|
@@ -3,19 +3,19 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int thread_count = 10;
|
||||
if(argc > 1)
|
||||
if (argc > 1)
|
||||
thread_count = atoi(argv[1]);
|
||||
|
||||
int howmany = 1000000;
|
||||
@@ -24,24 +24,23 @@ int main(int argc, char* argv[])
|
||||
FLAGS_log_dir = "logs";
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
|
||||
std::atomic<int > msg_counter {0};
|
||||
std::atomic<int> msg_counter{0};
|
||||
vector<thread> threads;
|
||||
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]()
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
while (true)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany) break;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
LOG(INFO) << "glog message #" << counter << ": This is some text for your pleasure";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
@@ -5,16 +5,14 @@
|
||||
|
||||
#include "glog/logging.h"
|
||||
|
||||
|
||||
int main(int, char* argv[])
|
||||
int main(int, char *argv[])
|
||||
{
|
||||
int howmany = 1000000;
|
||||
|
||||
|
||||
FLAGS_logtostderr = 0;
|
||||
FLAGS_log_dir = "logs";
|
||||
google::InitGoogleLogging(argv[0]);
|
||||
for(int i = 0 ; i < howmany; ++i)
|
||||
for (int i = 0; i < howmany; ++i)
|
||||
LOG(INFO) << "glog message # " << i << ": This is some text for your pleasure";
|
||||
|
||||
return 0;
|
||||
|
@@ -9,29 +9,26 @@ void CrusherLoop()
|
||||
while (true)
|
||||
{
|
||||
LOGF(INFO, "Some text to crush you machine. thread:");
|
||||
if(++counter % 1000000 == 0)
|
||||
if (++counter % 1000000 == 0)
|
||||
{
|
||||
std::cout << "Wrote " << counter << " entries" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::cout << "WARNING: This test will exaust all your machine memory and will crush it!" << std::endl;
|
||||
std::cout << "Are you sure you want to continue ? " << std::endl;
|
||||
char c;
|
||||
std::cin >> c;
|
||||
if (toupper( c ) != 'Y')
|
||||
if (toupper(c) != 'Y')
|
||||
return 0;
|
||||
|
||||
auto worker = g3::LogWorker::createLogWorker();
|
||||
auto handle= worker->addDefaultLogger(argv[0], "g3log.txt");
|
||||
auto handle = worker->addDefaultLogger(argv[0], "g3log.txt");
|
||||
g3::initializeLogging(worker.get());
|
||||
CrusherLoop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,32 +1,26 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include "utils.h"
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <g3log/g3log.hpp>
|
||||
#include <g3log/logworker.hpp>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
while (true)
|
||||
@@ -45,14 +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());
|
||||
}
|
||||
@@ -62,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 << "[g3log] 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 << "[g3log] 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
|
||||
@@ -78,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]);
|
||||
@@ -91,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;
|
||||
|
||||
@@ -102,12 +92,12 @@ int main(int argc, char** argv)
|
||||
threads_result[idx].reserve(g_iterations);
|
||||
}
|
||||
|
||||
const std::string g_path = "./" ;
|
||||
const std::string g_prefix_log_name = "g3log-performance-";
|
||||
const std::string g_measurement_dump = g_path + g_prefix_log_name + "_RESULT.txt";
|
||||
const std::string g_path = "./";
|
||||
const std::string g_prefix_log_name = "g3log-performance-";
|
||||
const std::string g_measurement_dump = g_path + g_prefix_log_name + "_RESULT.txt";
|
||||
|
||||
auto worker = g3::LogWorker::createLogWorker();
|
||||
auto handle= worker->addDefaultLogger(argv[0], "g3log.txt");
|
||||
auto handle = worker->addDefaultLogger(argv[0], "g3log.txt");
|
||||
g3::initializeLogging(worker.get());
|
||||
|
||||
auto start_time_application_total = std::chrono::high_resolution_clock::now();
|
||||
@@ -121,9 +111,8 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -5,15 +5,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
namespace utils {
|
||||
|
||||
template<typename T>
|
||||
inline std::string format(const T& value)
|
||||
template <typename T> inline std::string format(const T &value)
|
||||
{
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
@@ -22,8 +20,7 @@ inline std::string format(const T& value)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string format(const double & value)
|
||||
template <> inline std::string format(const double &value)
|
||||
{
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
@@ -32,4 +29,4 @@ inline std::string format(const double & value)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace utils
|
||||
|
@@ -3,25 +3,25 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
using namespace std::chrono;
|
||||
using clock=steady_clock;
|
||||
using clock = steady_clock;
|
||||
namespace spd = spdlog;
|
||||
|
||||
int thread_count = 10;
|
||||
if(argc > 1)
|
||||
if (argc > 1)
|
||||
thread_count = ::atoi(argv[1]);
|
||||
int howmany = 1000000;
|
||||
|
||||
@@ -29,31 +29,30 @@ int main(int argc, char* argv[])
|
||||
auto logger = spdlog::create<spd::sinks::simple_file_sink_mt>("file_logger", "logs/spd-bench-async.txt", false);
|
||||
logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
|
||||
|
||||
|
||||
std::atomic<int > msg_counter {0};
|
||||
std::atomic<int> msg_counter{0};
|
||||
vector<thread> threads;
|
||||
auto start = clock::now();
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]()
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
while (true)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany) break;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
logger->info("spdlog message #{}: This is some text for your pleasure", counter);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
for(auto &t:threads)
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
duration<float> delta = clock::now() - start;
|
||||
float deltaf = delta.count();
|
||||
auto rate = howmany/deltaf;
|
||||
auto rate = howmany / deltaf;
|
||||
|
||||
cout << "Total: " << howmany << std::endl;
|
||||
cout << "Threads: " << thread_count << std::endl;
|
||||
|
@@ -3,20 +3,19 @@
|
||||
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
||||
//
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int thread_count = 10;
|
||||
if(argc > 1)
|
||||
if (argc > 1)
|
||||
thread_count = std::atoi(argv[1]);
|
||||
|
||||
int howmany = 1000000;
|
||||
@@ -27,29 +26,26 @@ int main(int argc, char* argv[])
|
||||
|
||||
logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
|
||||
|
||||
std::atomic<int > msg_counter {0};
|
||||
std::atomic<int> msg_counter{0};
|
||||
std::vector<thread> threads;
|
||||
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]()
|
||||
{
|
||||
threads.push_back(std::thread([&]() {
|
||||
while (true)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany) break;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
logger->info("spdlog message #{}: This is some text for your pleasure", counter);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -5,16 +5,15 @@
|
||||
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
|
||||
int main(int, char* [])
|
||||
int main(int, char *[])
|
||||
{
|
||||
int howmany = 1000000;
|
||||
namespace spd = spdlog;
|
||||
///Create a file rotating logger with 5mb size max and 3 rotated files
|
||||
/// Create a file rotating logger with 5mb size max and 3 rotated files
|
||||
auto logger = spdlog::create<spd::sinks::simple_file_sink_st>("file_logger", "logs/spd-bench-st.txt", false);
|
||||
|
||||
logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
|
||||
for(int i = 0 ; i < howmany; ++i)
|
||||
for (int i = 0; i < howmany; ++i)
|
||||
logger->info("spdlog message #{} : This is some text for your pleasure", i);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -6,17 +6,16 @@
|
||||
//
|
||||
// bench.cpp : spdlog benchmarks
|
||||
//
|
||||
#include "spdlog/async_logger.h"
|
||||
#include "spdlog/sinks/null_sink.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "utils.h"
|
||||
#include <atomic>
|
||||
#include <cstdlib> // EXIT_FAILURE
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include "spdlog/spdlog.h"
|
||||
#include "spdlog/async_logger.h"
|
||||
#include "spdlog/sinks/null_sink.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
@@ -24,11 +23,9 @@ using namespace spdlog;
|
||||
using namespace spdlog::sinks;
|
||||
using namespace utils;
|
||||
|
||||
|
||||
|
||||
size_t bench_as(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int queue_size = 1048576;
|
||||
@@ -39,14 +36,13 @@ int main(int argc, char* argv[])
|
||||
try
|
||||
{
|
||||
|
||||
if(argc > 1)
|
||||
if (argc > 1)
|
||||
howmany = atoi(argv[1]);
|
||||
if (argc > 2)
|
||||
threads = atoi(argv[2]);
|
||||
threads = atoi(argv[2]);
|
||||
if (argc > 3)
|
||||
queue_size = atoi(argv[3]);
|
||||
|
||||
|
||||
cout << "\n*******************************************************************************\n";
|
||||
cout << "async logging.. " << threads << " threads sharing same logger, " << format(howmany) << " messages " << endl;
|
||||
cout << "*******************************************************************************\n";
|
||||
@@ -55,16 +51,15 @@ int main(int argc, char* argv[])
|
||||
|
||||
size_t total_rate = 0;
|
||||
|
||||
for(int i = 0; i < iters; ++i)
|
||||
for (int i = 0; i < iters; ++i)
|
||||
{
|
||||
//auto as = spdlog::daily_logger_st("as", "logs/daily_async");
|
||||
// auto as = spdlog::daily_logger_st("as", "logs/daily_async");
|
||||
auto as = spdlog::create<null_sink_st>("async(null-sink)");
|
||||
total_rate+= bench_as(howmany, as, threads);
|
||||
total_rate += bench_as(howmany, as, threads);
|
||||
spdlog::drop("async(null-sink)");
|
||||
}
|
||||
std::cout << endl;
|
||||
std::cout << "Avg rate: " << format(total_rate/iters) << "/sec" <<std::endl;
|
||||
|
||||
std::cout << "Avg rate: " << format(total_rate / iters) << "/sec" << std::endl;
|
||||
}
|
||||
catch (std::exception &ex)
|
||||
{
|
||||
@@ -75,37 +70,33 @@ int main(int argc, char* argv[])
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//return rate/sec
|
||||
// return rate/sec
|
||||
size_t bench_as(int howmany, std::shared_ptr<spdlog::logger> log, int thread_count)
|
||||
{
|
||||
cout << log->name() << "...\t\t" << flush;
|
||||
std::atomic<int > msg_counter {0};
|
||||
std::atomic<int> msg_counter{0};
|
||||
vector<thread> threads;
|
||||
auto start = system_clock::now();
|
||||
for (int t = 0; t < thread_count; ++t)
|
||||
{
|
||||
threads.push_back(std::thread([&]()
|
||||
{
|
||||
for(;;)
|
||||
threads.push_back(std::thread([&]() {
|
||||
for (;;)
|
||||
{
|
||||
int counter = ++msg_counter;
|
||||
if (counter > howmany) break;
|
||||
if (counter > howmany)
|
||||
break;
|
||||
log->info("Hello logger: msg number {}", counter);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
for (auto &t : threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
|
||||
auto delta = system_clock::now() - start;
|
||||
auto delta_d = duration_cast<duration<double>> (delta).count();
|
||||
auto delta_d = duration_cast<duration<double>>(delta).count();
|
||||
auto per_sec = size_t(howmany / delta_d);
|
||||
cout << format(per_sec) << "/sec" << endl;
|
||||
return per_sec;
|
||||
|
@@ -5,15 +5,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
namespace utils {
|
||||
|
||||
template<typename T>
|
||||
inline std::string format(const T& value)
|
||||
template <typename T> inline std::string format(const T &value)
|
||||
{
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
@@ -22,8 +20,7 @@ inline std::string format(const T& value)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<>
|
||||
inline std::string format(const double & value)
|
||||
template <> inline std::string format(const double &value)
|
||||
{
|
||||
static std::locale loc("");
|
||||
std::stringstream ss;
|
||||
@@ -32,4 +29,4 @@ inline std::string format(const double & value)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace utils
|
||||
|
Reference in New Issue
Block a user