Added the all flag to bench formatter

This commit is contained in:
gabime 2018-11-25 00:44:27 +02:00
parent 0ce670e45a
commit c251c4ccbb

View File

@ -28,9 +28,7 @@ void bench_formatter(benchmark::State &state, std::string pattern)
std::string logger_name = "logger-name";
const char *text = "Hello. This is some message with length of 80 ";
spdlog::details::log_msg msg(spdlog::source_loc{__FILE__, __LINE__}, &logger_name, spdlog::level::info, text);
// formatter->format(msg, dest);
// printf("%s\n", fmt::to_string(dest).c_str());
spdlog::details::log_msg msg(&logger_name, spdlog::level::info, text);
for (auto _ : state)
{
@ -73,15 +71,22 @@ void bench_formatters()
int main(int argc, char *argv[])
{
if (argc > 1) // bench given pattern
spdlog::set_pattern("[%^%l%$] %v");
if(argc != 2)
{
std::string pattern = argv[1];
benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
spdlog::error("Usage: {} format-flag (or \"all\" to bench all)", argv[0]);
exit(1);
}
else // bench all flags
std::string pattern = argv[1];
if(pattern == "all")
{
bench_formatters();
}
else
{
benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
}
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
}