added bench and example files

This commit is contained in:
gabi 2014-10-12 04:40:11 +03:00
parent f9425bb666
commit a7f046901d
4 changed files with 37 additions and 47 deletions

View File

@ -86,7 +86,6 @@
<ItemGroup>
<ClInclude Include="..\..\include\c11log\common.h" />
<ClInclude Include="..\..\include\c11log\details\blocking_queue.h" />
<ClInclude Include="..\..\include\c11log\details\factory.h" />
<ClInclude Include="..\..\include\c11log\details\fast_oss.h" />
<ClInclude Include="..\..\include\c11log\details\flush_helper.h" />
<ClInclude Include="..\..\include\c11log\details\line_logger.h" />
@ -94,6 +93,7 @@
<ClInclude Include="..\..\include\c11log\details\null_mutex.h" />
<ClInclude Include="..\..\include\c11log\details\os.h" />
<ClInclude Include="..\..\include\c11log\details\stack_buf.h" />
<ClInclude Include="..\..\include\c11log\factory.h" />
<ClInclude Include="..\..\include\c11log\formatter.h" />
<ClInclude Include="..\..\include\c11log\logger.h" />
<ClInclude Include="..\..\include\c11log\sinks\async_sink.h" />
@ -107,6 +107,7 @@
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\example\bench.cpp" />
<ClCompile Include="..\..\example\example.cpp" />
<ClCompile Include="stdafx.cpp" />
</ItemGroup>

View File

@ -69,12 +69,6 @@
<ClInclude Include="..\..\include\c11log\sinks\file_sinks.h">
<Filter>Header Files\c11log\sinks</Filter>
</ClInclude>
<ClInclude Include="..\..\include\c11log\details\factory.h">
<Filter>Header Files\c11log\details</Filter>
</ClInclude>
<ClInclude Include="..\..\include\c11log\sinks\isink.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\include\c11log\details\null_mutex.h">
<Filter>Header Files\c11log\details</Filter>
</ClInclude>
@ -90,6 +84,12 @@
<ClInclude Include="..\..\include\c11log\common.h">
<Filter>Header Files\c11log</Filter>
</ClInclude>
<ClInclude Include="..\..\include\c11log\sinks\isink.h">
<Filter>Header Files\c11log\sinks</Filter>
</ClInclude>
<ClInclude Include="..\..\include\c11log\factory.h">
<Filter>Header Files\c11log</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
@ -98,5 +98,8 @@
<ClCompile Include="..\..\example\example.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\example\bench.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -15,26 +15,26 @@ using namespace c11log;
using namespace utils;
int main(int argc, char* argv[])
int main2(int argc, char* argv[])
{
const unsigned int howmany = argc <= 1 ? 10000 : atoi(argv[1]);
const unsigned int howmany = argc <= 1 ? 1000000 : atoi(argv[1]);
logger cout_logger("example", std::make_shared<sinks::stderr_sink_mt>());
cout_logger.info() << "Hello logger";
//auto nullsink = std::make_shared<sinks::null_sink<std::mutex>>();
auto nullsink = std::make_shared<sinks::null_sink<details::null_mutex>>();
auto fsink = std::make_shared<sinks::rotating_file_sink_st>("log", "txt", 1024 * 1024 * 50, 5, 10);
auto as = std::make_shared<sinks::async_sink>(1000);
logger my_logger("my_logger", fsink);
logger my_logger("my_logger", nullsink);
auto start = system_clock::now();
for (unsigned int i = 1; i <= howmany; ++i)
my_logger.info() << "Hello logger: msg #" << i;
my_logger.info() << "Hello logger: msg #" << i << 1<<2<<3<<4<<5<<6<<7<<8<<9<<10<<11<<12<<13<<14<<15<<16<<17<<18<<19;
//my_logger.info("Hello logger: msg #",i,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
auto delta = system_clock::now() - start;

View File

@ -1,49 +1,35 @@
// example.cpp : Simple logger example
//
#include <mutex>
#define FFLOG_ENABLE_TRACE
#include <iostream>
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
#include "c11log/factory.h"
#include "c11log/sinks/stdout_sinks.h"
#include "c11log/sinks/null_sink.h"
#include "utils.h"
using std::cout;
using std::endl;
using namespace std::chrono;
using namespace c11log;
using namespace utils;
#include "c11log/sinks/file_sinks.h"
using namespace std;
int main(int argc, char* argv[])
{
const unsigned int howmany = argc <= 1 ? 10000 : atoi(argv[1]);
logger cout_logger("example", std::make_shared<sinks::stderr_sink_mt>());
cout_logger.info() << "Hello logger";
//auto nullsink = std::make_shared<sinks::null_sink<std::mutex>>();
auto nullsink = std::make_shared<sinks::null_sink<details::null_mutex>>();
auto fsink = std::make_shared<sinks::rotating_file_sink_st>("log", "txt", 1024*1024*50 , 5, 10);
auto as = std::make_shared<sinks::async_sink>(1000);
auto console = c11log::factory::stdout_logger();
auto file = c11log::factory::simple_file_logger("log.txt");
auto rotating= c11log::factory::rotating_file_logger("myrotating", "txt", 1024*1024*5, 5, 1);
auto daily = c11log::factory::daily_file_logger("dailylog", "txt", 1, "daily_logger");
logger my_logger("my_logger", fsink);
//console->info() << "This is variadic ", " func, ", 123 << " YES";
FFLOG_TRACE(console, "This is ", 1);
auto start = system_clock::now();
for (unsigned int i = 1; i <= howmany; ++i)
my_logger.info() << "Hello logger: msg #" << i;
file->info("Hello file log");
rotating->info("Hello rotating log");
daily->info("Hello daily log");
//multi sink logger: file + console
auto sink1= std::make_shared<c11log::sinks::stdout_sink_mt>();
auto sink2 = std::make_shared<c11log::sinks::daily_file_sink_mt>("rotating", "txt");
c11log::logger combined("combined", { sink1, sink2 });
auto delta = system_clock::now() - start;
auto delta_d = duration_cast<duration<double>> (delta).count();
cout << "Total:" << format(howmany) << endl;
cout << "Delta:" << format(delta_d) << endl;
cout << "Rate:" << format(howmany / delta_d) << "/sec" << endl;
return 0;
}