From f7a9a57ee13be5061381eff97ab52f775daf4756 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 8 Dec 2024 17:26:43 +0800 Subject: [PATCH] feat: mirror benchmark of CommonCode --- src/core/benchmark/common_code.cc | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/core/benchmark/common_code.cc b/src/core/benchmark/common_code.cc index 8c54c8e..ae7b623 100644 --- a/src/core/benchmark/common_code.cc +++ b/src/core/benchmark/common_code.cc @@ -56,7 +56,7 @@ static void CommonCodeCheck(benchmark::State &state) { const auto samples = common_code_samples(state.range(0)); for (auto _ : state) { for (const auto code : samples) { - volatile auto tmp = CommonCode::check(code); + benchmark::DoNotOptimize(CommonCode::check(code)); } } state.SetItemsProcessed(state.iterations() * state.range(0)); @@ -66,7 +66,6 @@ static void CommonCodeSerialize(benchmark::State &state) { const auto samples = common_code_samples(state.range(0)); for (auto _ : state) { for (const auto code : samples) { - // volatile auto ret = CommonCode::string_encode(code); benchmark::DoNotOptimize(CommonCode::string_encode(code)); } } @@ -89,7 +88,6 @@ static void CommonCodeSerializeShorten(benchmark::State &state) { const auto samples = common_code_samples(state.range(0)); for (auto _ : state) { for (const auto code : samples) { - // volatile auto ret = CommonCode::string_encode_shorten(code); benchmark::DoNotOptimize(CommonCode::string_encode_shorten(code)); } } @@ -108,11 +106,46 @@ static void CommonCodeDeserializeShorten(benchmark::State &state) { state.SetItemsProcessed(state.iterations() * state.range(0)); } -// BENCHMARK(CommonCodeCheck)->Range(64, 1024); +static void CommonCodeCheckMirror(benchmark::State &state) { + const auto samples = common_code_samples(state.range(0)); + for (auto _ : state) { + for (const auto code : samples) { + benchmark::DoNotOptimize(CommonCode::check_mirror(code)); + } + } + state.SetItemsProcessed(state.iterations() * state.range(0)); +} + +static void CommonCodeVerticalMirror(benchmark::State &state) { + const auto samples = common_code_samples(state.range(0)); + for (auto _ : state) { + for (const auto code : samples) { + benchmark::DoNotOptimize(CommonCode::get_vertical_mirror(code)); + } + } + state.SetItemsProcessed(state.iterations() * state.range(0)); +} + +static void CommonCodeHorizontalMirror(benchmark::State &state) { + const auto samples = common_code_samples(state.range(0)); + for (auto _ : state) { + for (const auto code : samples) { + benchmark::DoNotOptimize(CommonCode::get_horizontal_mirror(code)); + } + } + state.SetItemsProcessed(state.iterations() * state.range(0)); +} + +// BENCHMARK(CommonCodeCheck)->Range(8, 256); // BENCHMARK(CommonCodeSerialize)->Range(8, 256); // BENCHMARK(CommonCodeDeserialize)->Range(8, 256); // BENCHMARK(CommonCodeSerializeShorten)->Range(8, 256); -BENCHMARK(CommonCodeDeserializeShorten)->Range(8, 256); +// BENCHMARK(CommonCodeDeserializeShorten)->Range(8, 256); + +// BENCHMARK(CommonCodeCheckMirror)->Range(64, 1024); + +BENCHMARK(CommonCodeVerticalMirror)->Range(8, 256); +BENCHMARK(CommonCodeHorizontalMirror)->Range(8, 256); BENCHMARK_MAIN();