Skip to content

Commit

Permalink
Remove duplicate benchmark checks and add float benchmark checks
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-webb committed Nov 16, 2023
1 parent 4b20aa6 commit 4d7531e
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions src/test/cpp/benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <fmt/format.h>
#include <benchmark/benchmark.h>
#include <thread>
#include <cstdlib>

using namespace log4cxx;

Expand Down Expand Up @@ -116,18 +117,8 @@ BENCHMARK_DEFINE_F(benchmarker, logDisabledTrace)(benchmark::State& state)
LOG4CXX_TRACE( m_logger, LOG4CXX_STR("This is a static string to see what happens"));
}
}
BENCHMARK_REGISTER_F(benchmarker, logDisabledTrace)->Name("Logging disabled trace")->MinWarmUpTime(benchmarker::warmUpSeconds());
BENCHMARK_REGISTER_F(benchmarker, logDisabledTrace)->Name("Logging disabled trace")->Threads(benchmarker::threadCount());

BENCHMARK_DEFINE_F(benchmarker, logDisabledDebug)(benchmark::State& state)
{
m_logger->setLevel(Level::getInfo());
for (auto _ : state)
{
LOG4CXX_DEBUG(m_logger, LOG4CXX_STR("This is a static string to see what happens"));
}
}
BENCHMARK_REGISTER_F(benchmarker, logDisabledDebug)->Name("Logging disabled debug");
BENCHMARK_REGISTER_F(benchmarker, logDisabledTrace)->Name("Testing disabled logging request")->MinWarmUpTime(benchmarker::warmUpSeconds());
BENCHMARK_REGISTER_F(benchmarker, logDisabledTrace)->Name("Testing disabled logging request")->Threads(benchmarker::threadCount());

BENCHMARK_DEFINE_F(benchmarker, logStaticString)(benchmark::State& state)
{
Expand All @@ -137,60 +128,65 @@ BENCHMARK_DEFINE_F(benchmarker, logStaticString)(benchmark::State& state)
LOG4CXX_INFO( m_logger, LOG4CXX_STR("This is a static string to see what happens"));
}
}
BENCHMARK_REGISTER_F(benchmarker, logStaticString)->Name("Logging info static string");
BENCHMARK_REGISTER_F(benchmarker, logStaticString)->Name("Logging static string");

BENCHMARK_DEFINE_F(benchmarker, logEnabledDebug)(benchmark::State& state)
#if LOG4CXX_HAS_FMT
BENCHMARK_DEFINE_F(benchmarker, logStaticStringFMT)(benchmark::State& state)
{
m_logger->setLevel( Level::getDebug() );
for (auto _ : state)
{
LOG4CXX_DEBUG( m_logger, LOG4CXX_STR("This is a static string to see what happens"));
LOG4CXX_INFO_FMT(m_logger, "This is a static string to see what happens");
}
}
BENCHMARK_REGISTER_F(benchmarker, logEnabledDebug)->Name("Logging enabled debug static string");
BENCHMARK_REGISTER_F(benchmarker, logStaticStringFMT)->Name("Logging static string with FMT");

BENCHMARK_DEFINE_F(benchmarker, logEnabledTrace)(benchmark::State& state)
BENCHMARK_DEFINE_F(benchmarker, logIntValueFMT)(benchmark::State& state)
{
m_logger->setLevel( Level::getTrace() );
int x = 0;
for (auto _ : state)
{
LOG4CXX_DEBUG( m_logger, LOG4CXX_STR("This is a static string to see what happens"));
LOG4CXX_INFO_FMT( m_logger, "Hello: msg number {}", ++x);
}
}
BENCHMARK_REGISTER_F(benchmarker, logEnabledTrace)->Name("Logging enabled trace static string");
BENCHMARK_REGISTER_F(benchmarker, logIntValueFMT)->Name("Logging int value with FMT");
BENCHMARK_REGISTER_F(benchmarker, logIntValueFMT)->Name("Logging int value with FMT")->Threads(benchmarker::threadCount());

#if LOG4CXX_HAS_FMT
BENCHMARK_DEFINE_F(benchmarker, logStaticStringFMT)(benchmark::State& state)
BENCHMARK_DEFINE_F(benchmarker, logIntPlusFloatValueFMT)(benchmark::State& state)
{
int x = 0;
for (auto _ : state)
{
LOG4CXX_INFO_FMT(m_logger, "This is a static string to see what happens");
auto f = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
LOG4CXX_INFO_FMT( m_logger, "Hello: msg number {} pseudo-random float {:.3f}", ++x, f);
}
}
BENCHMARK_REGISTER_F(benchmarker, logStaticStringFMT)->Name("Logging static string with FMT");
BENCHMARK_REGISTER_F(benchmarker, logIntPlusFloatValueFMT)->Name("Logging int+float with FMT");
BENCHMARK_REGISTER_F(benchmarker, logIntPlusFloatValueFMT)->Name("Logging int+float with FMT")->Threads(benchmarker::threadCount());
#endif

BENCHMARK_DEFINE_F(benchmarker, logIntValueFMT)(benchmark::State& state)
BENCHMARK_DEFINE_F(benchmarker, logIntValueStream)(benchmark::State& state)
{
int x = 0;
for (auto _ : state)
{
LOG4CXX_INFO_FMT( m_logger, "Hello m_logger: msg number {}", ++x);
LOG4CXX_INFO( m_logger, "Hello: msg number " << ++x);
}
}
BENCHMARK_REGISTER_F(benchmarker, logIntValueFMT)->Name("Logging int value with FMT");
BENCHMARK_REGISTER_F(benchmarker, logIntValueFMT)->Name("Logging int value with FMT")->Threads(benchmarker::threadCount());
#endif
BENCHMARK_REGISTER_F(benchmarker, logIntValueStream)->Name("Logging int value with std::ostream");
BENCHMARK_REGISTER_F(benchmarker, logIntValueStream)->Name("Logging int value with std::ostream")->Threads(benchmarker::threadCount());

BENCHMARK_DEFINE_F(benchmarker, logIntValueStream)(benchmark::State& state)
BENCHMARK_DEFINE_F(benchmarker, logIntPlusFloatStream)(benchmark::State& state)
{
int x = 0;
for (auto _ : state)
{
LOG4CXX_INFO( m_logger, "Hello m_logger: msg number " << ++x);
auto f = static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
LOG4CXX_INFO( m_logger, "Hello: msg number " << ++x
<< " pseudo-random float " << std::setprecision(3) << std::fixed << f);
}
}
BENCHMARK_REGISTER_F(benchmarker, logIntValueStream)->Name("Logging int value with std::ostream");
BENCHMARK_REGISTER_F(benchmarker, logIntValueStream)->Name("Logging int value with std::ostream")->Threads(benchmarker::threadCount());
BENCHMARK_REGISTER_F(benchmarker, logIntPlusFloatStream)->Name("Logging int+float with std::ostream");
BENCHMARK_REGISTER_F(benchmarker, logIntPlusFloatStream)->Name("Logging int+float with std::ostream")->Threads(benchmarker::threadCount());

template <class ...Args>
void logWithConversionPattern(benchmark::State& state, Args&&... args)
Expand Down

0 comments on commit 4d7531e

Please sign in to comment.