80 lines
2.5 KiB
C++
80 lines
2.5 KiB
C++
#include "catch/catch.hpp"
|
|
#include "lib/utils/bts_chrono.h"
|
|
#include "lib/logging/logging.h"
|
|
|
|
namespace bts {
|
|
int logging_tests ;
|
|
|
|
TEST_CASE("Logging Tests","[logging] [benchmark]") {
|
|
|
|
auto sz = 1000000;
|
|
log::Filter f;
|
|
for (auto &l : f)
|
|
l = Diag;
|
|
log::LoggingConfig cfg;
|
|
cfg.logger_initial_queue_size = sz*10;
|
|
cfg.sinks["null_sink"] = std::make_pair ( [](log::LogMsg const&) {}, f );
|
|
log::configure_logging(cfg);
|
|
LOG(Gen,Info,"Kicking things off");
|
|
|
|
SECTION("timestamp_interpolation")
|
|
{
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz ;i++)
|
|
LOG(Gen,Info,"Hello World. It is now: {0}",bts::Timer::now());
|
|
auto stop = bts::Timer::now();
|
|
std::cout << "\tLogging: ns/msg for log with timestamps: "
|
|
<< bts::ns_diff(stop,start) / sz
|
|
<< " tt: " << bts::ns_diff(stop,start)
|
|
<< std::endl;
|
|
}
|
|
|
|
SECTION("int_interpolation")
|
|
{
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz;i++)
|
|
LOG(Gen,Info,"Hello World. This is interpolating a number {0}",12);
|
|
auto stop = bts::Timer::now();
|
|
std::cout << "\tLogging ns/msg for log with simple number interpolation: "
|
|
<< bts::ns_diff(stop,start) / sz
|
|
<< " tt: " << bts::ns_diff(stop,start)
|
|
<< std::endl;
|
|
}
|
|
|
|
SECTION("large_string_interpolation")
|
|
{
|
|
std::array<std::string,8> strs;
|
|
int i = 0;
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
strs[i++] = "aaaaaaaaaaaaaaaaa";
|
|
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz;i++)
|
|
LOG(Gen,Info,"Hello World. This is interpolating a string ",strs[i & 0x00000007] );
|
|
auto stop = bts::Timer::now();
|
|
std::cout << "\tLogging ns/msg for log with large string interpolation: " << bts::ns_diff(stop,start) / sz
|
|
<< " tt: " << bts::ns_diff(stop,start)
|
|
<< std::endl;
|
|
}
|
|
|
|
SECTION("log_skipping")
|
|
{
|
|
auto start = bts::Timer::now();
|
|
for (int i = 0; i < sz;i++)
|
|
LOG(Gen,Diag,"Hello World. I am {} years old!",i);
|
|
auto stop = bts::Timer::now();
|
|
std::cout << "\tLogging ns/msg for log skipping: "
|
|
<< bts::ns_diff(stop,start) / sz
|
|
<< " tt: " << bts::ns_diff(stop,start)
|
|
<< std::endl;
|
|
}
|
|
}
|
|
|
|
}
|