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/bench/easylogging-bench-mt.cpp

67 lines
1.6 KiB
C++

10 years ago
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
8 years ago
#include <atomic>
#include <chrono>
#include <iostream>
11 years ago
#include <thread>
#include <vector>
#define ELPP_THREAD_SAFE
11 years ago
#include "easylogging++.h"
#include "easylogging++.cc"
INITIALIZE_EASYLOGGINGPP
11 years ago
using namespace std;
8 years ago
int main(int argc, char *argv[])
11 years ago
{
using namespace std::chrono;
using clock = steady_clock;
11 years ago
11 years ago
int thread_count = 10;
8 years ago
if (argc > 1)
11 years ago
thread_count = atoi(argv[1]);
int howmany = 1000000;
// Load configuration from file
el::Configurations conf("easyl-mt.conf");
11 years ago
el::Loggers::reconfigureLogger("default", conf);
8 years ago
std::atomic<int> msg_counter{0};
11 years ago
vector<thread> threads;
auto start = clock::now();
11 years ago
for (int t = 0; t < thread_count; ++t)
{
8 years ago
threads.push_back(std::thread([&]() {
11 years ago
while (true)
{
int counter = ++msg_counter;
8 years ago
if (counter > howmany)
break;
11 years ago
LOG(INFO) << "easylog message #" << counter << ": This is some text for your pleasure";
}
}));
}
8 years ago
for (auto &t : threads)
11 years ago
{
t.join();
}
duration<float> delta = clock::now() - start;
float deltaf = delta.count();
auto rate = howmany / deltaf;
std::cout << "Total: " << howmany << std::endl;
std::cout << "Threads: " << thread_count << std::endl;
std::cout << "Delta = " << deltaf << " seconds" << std::endl;
std::cout << "Rate = " << rate << "/sec" << std::endl;
11 years ago
return 0;
11 years ago
}