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

50 lines
985 B
C++

10 years ago
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
8 years ago
#include <atomic>
11 years ago
#include <thread>
#include <vector>
#include "glog/logging.h"
using namespace std;
8 years ago
int main(int argc, char *argv[])
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;
FLAGS_logtostderr = 0;
FLAGS_log_dir = "logs";
google::InitGoogleLogging(argv[0]);
8 years ago
std::atomic<int> msg_counter{0};
11 years ago
vector<thread> threads;
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) << "glog message #" << counter << ": This is some text for your pleasure";
}
}));
}
8 years ago
for (auto &t : threads)
11 years ago
{
t.join();
};
return 0;
11 years ago
}