mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-15 16:35:45 +08:00
Updated formatter-bench
This commit is contained in:
parent
7068c45115
commit
e601ebe19b
@ -50,9 +50,17 @@ void bench_formatters()
|
|||||||
for(auto &flag:all_flags)
|
for(auto &flag:all_flags)
|
||||||
{
|
{
|
||||||
auto pattern = std::string("%") + flag;
|
auto pattern = std::string("%") + flag;
|
||||||
benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern)->Iterations(2500000);
|
benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
|
||||||
|
//bench left padding
|
||||||
|
pattern = std::string("%16") + flag;
|
||||||
|
benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
|
||||||
|
|
||||||
|
//bench center padding
|
||||||
|
pattern = std::string("%=16") + flag;
|
||||||
|
benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// complex patterns
|
// complex patterns
|
||||||
std::vector<std::string> patterns = {
|
std::vector<std::string> patterns = {
|
||||||
"[%D %X] [%l] [%n] %v",
|
"[%D %X] [%l] [%n] %v",
|
||||||
@ -65,34 +73,19 @@ void bench_formatters()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bench_padders()
|
|
||||||
{
|
|
||||||
using spdlog::details::padding_info;
|
|
||||||
std::vector<size_t> sizes = {0, 2, 4, 8, 16, 32, 64, 128};
|
|
||||||
|
|
||||||
for (auto size : sizes)
|
|
||||||
{
|
|
||||||
size_t wrapped_size = 8;
|
|
||||||
size_t padding_size = wrapped_size + size;
|
|
||||||
|
|
||||||
std::string title = "scoped_pad::left::" + std::to_string(size);
|
|
||||||
|
|
||||||
benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::left));
|
|
||||||
|
|
||||||
title = "scoped_pad::right::" + std::to_string(size);
|
|
||||||
benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::right));
|
|
||||||
|
|
||||||
title = "scoped_pad::center::" + std::to_string(size);
|
|
||||||
benchmark::RegisterBenchmark(title.c_str(), bench_scoped_pad, wrapped_size, padding_info(padding_size, padding_info::center));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
bench_formatters();
|
|
||||||
//bench_padders();
|
if(argc > 1) //bench given pattern
|
||||||
|
{
|
||||||
|
std::string pattern = argv[1];
|
||||||
|
benchmark::RegisterBenchmark(pattern.c_str(), bench_formatter, pattern);
|
||||||
|
}
|
||||||
|
else //bench all flags
|
||||||
|
{
|
||||||
|
bench_formatters();
|
||||||
|
}
|
||||||
benchmark::Initialize(&argc, argv);
|
benchmark::Initialize(&argc, argv);
|
||||||
benchmark::RunSpecifiedBenchmarks();
|
benchmark::RunSpecifiedBenchmarks();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user