glog-bench.cpp 870 Bytes
Newer Older
gabime's avatar
gabime committed
1 2 3 4
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
gabime's avatar
gabime committed
5

6 7 8
#include <chrono>
#include <iostream>

gabime's avatar
gabime committed
9 10
#include "glog/logging.h"

gabime's avatar
gabime committed
11
int main(int, char *argv[])
gabime's avatar
gabime committed
12
{
13 14 15
    using namespace std::chrono;
    using clock = steady_clock;

gabime's avatar
gabime committed
16
    int howmany = 1000000;
gabime's avatar
gabime committed
17

gabime's avatar
gabime committed
18 19 20
    FLAGS_logtostderr = 0;
    FLAGS_log_dir = "logs";
    google::InitGoogleLogging(argv[0]);
21
    auto start = clock::now();
gabime's avatar
gabime committed
22
    for (int i = 0; i < howmany; ++i)
23 24 25 26 27 28 29 30 31
        LOG(INFO) << "glog message #" << i << ": This is some text for your pleasure";

    duration<float> delta = clock::now() - start;
    float deltaf = delta.count();
    auto rate = howmany / deltaf;

    std::cout << "Total: " << howmany << std::endl;
    std::cout << "Delta = " << deltaf << " seconds" << std::endl;
    std::cout << "Rate = " << rate << "/sec" << std::endl;
gabime's avatar
gabime committed
32

gabime's avatar
gabime committed
33
    return 0;
gabime's avatar
gabime committed
34
}