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/g2log-async.cpp

61 lines
1.5 KiB
C++

10 years ago
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
11 years ago
#include <atomic>
#include <chrono>
8 years ago
#include <iostream>
#include <thread>
#include <vector>
11 years ago
#include "g2log.h"
8 years ago
#include "g2logworker.h"
11 years ago
using namespace std;
template<typename T> std::string format(const T &value);
11 years ago
8 years ago
int main(int argc, char *argv[])
11 years ago
{
11 years ago
using namespace std::chrono;
8 years ago
using clock = steady_clock;
11 years ago
int thread_count = 10;
8 years ago
if (argc > 1)
11 years ago
thread_count = atoi(argv[1]);
int howmany = 1000000;
g2LogWorker g2log(argv[0], "logs");
g2::initializeLogging(&g2log);
8 years ago
std::atomic<int> msg_counter{0};
11 years ago
vector<thread> threads;
auto start = clock::now();
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) << "g2log 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();
8 years ago
auto rate = howmany / deltaf;
11 years ago
cout << "Total: " << howmany << std::endl;
cout << "Threads: " << thread_count << std::endl;
std::cout << "Delta = " << deltaf << " seconds" << std::endl;
std::cout << "Rate = " << rate << "/sec" << std::endl;
11 years ago
}