2018-03-20 00:17:26 +08:00
|
|
|
//
|
|
|
|
// Copyright(c) 2015 Gabi Melman.
|
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "log4cpp/Appender.hh"
|
2018-04-06 07:24:07 +08:00
|
|
|
#include "log4cpp/BasicLayout.hh"
|
|
|
|
#include "log4cpp/Category.hh"
|
2018-03-20 00:17:26 +08:00
|
|
|
#include "log4cpp/FileAppender.hh"
|
|
|
|
#include "log4cpp/Layout.hh"
|
|
|
|
#include "log4cpp/PatternLayout.hh"
|
2018-04-06 07:24:07 +08:00
|
|
|
#include "log4cpp/Priority.hh"
|
2018-03-20 00:17:26 +08:00
|
|
|
|
|
|
|
int main(int, char *[])
|
|
|
|
{
|
|
|
|
using namespace std::chrono;
|
|
|
|
using clock = steady_clock;
|
|
|
|
|
|
|
|
int howmany = 1000000;
|
|
|
|
|
2018-04-06 07:24:07 +08:00
|
|
|
log4cpp::Appender *appender = new log4cpp::FileAppender("default", "logs/log4cpp-bench.log");
|
2018-03-20 00:17:26 +08:00
|
|
|
log4cpp::PatternLayout *layout = new log4cpp::PatternLayout();
|
|
|
|
layout->setConversionPattern("%d{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n");
|
|
|
|
appender->setLayout(layout);
|
|
|
|
|
2018-04-06 07:24:07 +08:00
|
|
|
log4cpp::Category &root = log4cpp::Category::getRoot();
|
2018-03-20 00:17:26 +08:00
|
|
|
root.addAppender(appender);
|
|
|
|
root.setPriority(log4cpp::Priority::INFO);
|
|
|
|
|
|
|
|
auto start = clock::now();
|
|
|
|
for (int i = 0; i < howmany; ++i)
|
|
|
|
root << log4cpp::Priority::INFO << "log4cpp 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;
|
|
|
|
|
|
|
|
root.shutdown();
|
|
|
|
return 0;
|
|
|
|
}
|