-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathasync_format.cpp
49 lines (39 loc) · 1.46 KB
/
async_format.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Created by Ivan Shynkarenka on 28.09.2016
//
#include "benchmark/cppbenchmark.h"
#include "logging/config.h"
#include "logging/logger.h"
using namespace CppCommon;
using namespace CppLogging;
const auto settings = CppBenchmark::Settings().ThreadsRange(1, 8, [](int from, int to, int& result) { int r = result; result *= 2; return r; });
class LogConfigFixture
{
protected:
LogConfigFixture()
{
auto binary_sink = std::make_shared<AsyncWaitFreeProcessor>(std::make_shared<BinaryLayout>());
binary_sink->appenders().push_back(std::make_shared<FileAppender>(_file));
Config::ConfigLogger("binary", binary_sink);
Config::Startup();
}
~LogConfigFixture()
{
Config::Shutdown();
if (_file.IsFileExists())
File::Remove(_file);
}
private:
File _file{"test.bin.log"};
};
BENCHMARK_THREADS_FIXTURE(LogConfigFixture, "Format(int, double, string)", settings)
{
thread_local Logger logger = Config::CreateLogger("binary");
logger.Info(CppCommon::format("Test {}.{}.{} message", context.metrics().total_operations(), context.metrics().total_operations() / 1000.0, context.name()));
}
BENCHMARK_THREADS_FIXTURE(LogConfigFixture, "Serialize(int, double, string)", settings)
{
thread_local Logger logger = Config::CreateLogger("binary");
logger.Info("Test {}.{}.{} message", context.metrics().total_operations(), context.metrics().total_operations() / 1000.0, context.name());
}
BENCHMARK_MAIN()