spdlog/example/bench.cpp

45 lines
1.4 KiB
C++
Raw Normal View History

2014-10-10 18:15:26 -04:00
// example.cpp : Simple logger example
//
#include <mutex>
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/stdout_sinks.h"
#include "c11log/sinks/null_sink.h"
#include "utils.h"
using namespace std::chrono;
using namespace c11log;
using namespace utils;
2014-10-18 12:04:24 -04:00
int main(int argc, char* argv[])
2014-10-10 18:15:26 -04:00
{
const unsigned int howmany = argc <= 1 ? 500000 : atoi(argv[1]);
2014-10-10 18:15:26 -04:00
2014-10-14 01:00:39 -04:00
//std::string pattern = "%Y:%m:%d %H:%M:%S.%e ---> [%n:%l] %t";
//auto formatter = std::make_shared<details::pattern_formatter>(pattern);
2014-10-10 18:15:26 -04:00
2014-10-14 01:00:39 -04:00
logger cout_logger("bench", { std::make_shared<sinks::stderr_sink_mt>() });
cout_logger.info() << "Hello logger " << 1234;
2014-10-10 18:15:26 -04:00
2014-10-14 01:00:39 -04:00
auto nullsink = std::make_shared<sinks::null_sink_st>();
2014-10-18 12:04:24 -04:00
auto rotating = std::make_shared<sinks::rotating_file_sink_mt>("myrotating", "txt", 1024 * 1024 * 5, 5, 1);
2014-10-10 18:15:26 -04:00
2014-10-18 12:04:24 -04:00
logger my_logger("my_logger", { rotating });
2014-10-10 18:15:26 -04:00
auto start = system_clock::now();
for (unsigned int i = 1; i <= howmany; ++i)
my_logger.info() << "Hello logger: msg #" << i;
2014-10-10 18:15:26 -04:00
auto delta = system_clock::now() - start;
auto delta_d = duration_cast<duration<double>> (delta).count();
2014-10-18 09:05:41 -04:00
cout_logger.info("Total:") << format(howmany);
cout_logger.info("Delta:") << format(delta_d);
cout_logger.info("Rate:") << format(howmany / delta_d) << "/sec";
2014-10-10 18:15:26 -04:00
return 0;
}