You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
spdlog/src/test.cpp

63 lines
1.8 KiB
C++

// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
12 years ago
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/stdout_sinks.h"
#include "utils.h"
12 years ago
int main(int argc, char* argv[])
{
12 years ago
using namespace std::chrono;
12 years ago
int nthreads = argc > 1 ? atoi(argv[1]) : 1;
12 years ago
int nlines = argc > 2 ? atoi(argv[2]) : 1000000;
auto null_sink = std::make_shared<c11log::sinks::null_sink>();
12 years ago
auto stdout_sink = std::make_shared<c11log::sinks::stdout_sink>();
12 years ago
auto async = std::make_shared<c11log::sinks::async_sink>(100);
12 years ago
//auto fsink = std::make_shared<c11log::sinks::rotating_file_sink>("newlog", "txt", 1024*1024*10 , 2);
12 years ago
auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
12 years ago
12 years ago
async->add_sink(fsink);
12 years ago
//async->add_sink(null_sink);
12 years ago
c11log::logger logger("test");
logger.add_sink(async);
12 years ago
12 years ago
std::vector<std::thread*> threads;
12 years ago
std::cout << "Starting " << nthreads << " threads x " << utils::format(nlines) << " lines each.." << std::endl;
12 years ago
for (int i = 0; i < nthreads; i++)
{
12 years ago
auto t = new std::thread([&logger, nlines]() {
for(int i = 0 ; i < nlines; ++i)
{
12 years ago
logger.info() << "Hello from thread " << std::this_thread::get_id() << "\tcounter: " << i ;
12 years ago
}
});
12 years ago
threads.push_back(t);
}
12 years ago
12 years ago
auto stime = steady_clock::now();
12 years ago
for(auto t:threads)
t->join();
12 years ago
auto delta = steady_clock::now() - stime;
auto delta_seconds = duration_cast<milliseconds>(delta).count()/1000.0;
auto total = nthreads*nlines;
std::cout << "Total: " << utils::format(total) << " = " << utils::format(total/delta_seconds) << "/sec" << std::endl;
async->shutdown(seconds(1));
12 years ago
return 0;
}