added padder bench

This commit is contained in:
gabime 2018-11-11 00:52:21 +02:00
parent ba4ed0eb7f
commit 2ba4b23b85
3 changed files with 104 additions and 5 deletions

View File

@ -1,9 +1,9 @@
CXX ?= g++
CXXFLAGS = -march=native -Wall -Wextra -pedantic -Wconversion -std=c++11 -pthread -I../include -fmax-errors=1
CXX_RELEASE_FLAGS = -Ofast -flto -Wl,--no-as-needed
CXX_RELEASE_FLAGS = -O3 -flto -Wl,--no-as-needed
binaries=bench latency async_bench
binaries=padder_bench
all: $(binaries)
@ -17,6 +17,10 @@ async_bench: async_bench.cpp
latency: latency.cpp
$(CXX) latency.cpp -o latency $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -lbenchmark
padder_bench: padder_bench.cpp
$(CXX) padder_bench.cpp -o padder_bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -lbenchmark
.PHONY: clean

72
bench/padder_bench.cpp Normal file
View File

@ -0,0 +1,72 @@
//
// Copyright(c) 2018 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
//
// latency.cpp : spdlog latency benchmarks
//
#include "benchmark/benchmark.h"
#include "spdlog/spdlog.h"
#include "spdlog/details/pattern_formatter.h"
void bench_scoped_pad(benchmark::State &state, size_t wrapped_size, spdlog::details::padding_info padinfo)
{
fmt::memory_buffer dest;
for (auto _ : state)
{
{
spdlog::details::scoped_pad p(wrapped_size, padinfo, dest);
benchmark::DoNotOptimize(p);
}
// if(dest.size() != (padinfo.width_-wrapped_size))
// {
// printf("NOT GOOD wrapped_size=%zu\t padinfo.width= %zu\tdest = %zu\n", wrapped_size, padinfo.width_, dest.size());
// }
dest.clear();
}
}
int main(int argc, char *argv[]) {
using spdlog::details::padding_info;
spdlog::set_pattern("[tid %t] %v");
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));
}
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
}

View File

@ -28,9 +28,32 @@ void clone_example();
int main(int, char *[])
{
spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
spdlog::warn("Easy padding in numbers like {:08d}", 12);
spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42);
spdlog::set_pattern("[%-8v]");
spdlog::info("LEFT");
spdlog::info("123");
spdlog::info("1234");
spdlog::info("12345678");
spdlog::info("123456789");
spdlog::set_pattern("[%=8v]");
spdlog::info("");
spdlog::info("CENTER");
spdlog::info("123");
spdlog::info("1234");
spdlog::info("12345678");
spdlog::info("123456789");
spdlog::set_pattern("[%8v]");
spdlog::info("");
spdlog::info("RIGHT");
spdlog::info("123");
spdlog::info("1234");
spdlog::info("12345678");
spdlog::info("123456789");
return 0;
spdlog::info("Support for floats {:03.2f}", 1.23456);
spdlog::info("Positional args are {1} {0}..", "too", "supported");
spdlog::info("{:>8} aligned, {:>8} aligned", "right", "left");