From 2570c5d0f4720a0ae5661d0e44d2637eb780c236 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Thu, 2 Mar 2023 19:15:58 +0800 Subject: [PATCH] feat: mirror functions benchmark --- src/klotski_core/benchmark/benchmark.cc | 46 +++++++++++++++++++++++++ src/klotski_core/benchmark/benchmark.h | 10 +++--- src/klotski_core/ffi/tmain.cc | 9 +++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/klotski_core/benchmark/benchmark.cc b/src/klotski_core/benchmark/benchmark.cc index 520aa60..4da3dbb 100644 --- a/src/klotski_core/benchmark/benchmark.cc +++ b/src/klotski_core/benchmark/benchmark.cc @@ -226,3 +226,49 @@ double Benchmark::short_code_to_common_code_fast(TIME format) noexcept { } return time_format(start, format) / (double)all_short_codes.size(); } + +/// ---------------------------- Benchmark Mirror ----------------------------- + +double Benchmark::vertical_mirror_check(TIME format) noexcept { + if (!data_ready) { + return -1; // data no ready -> skip + } + auto start = clock(); + for (auto &&raw_code : all_raw_codes) { + raw_code.is_vertical_mirror(); + } + return time_format(start, format) / (double)all_raw_codes.size(); +} + +double Benchmark::horizontal_mirror_check(TIME format) noexcept { + if (!data_ready) { + return -1; // data no ready -> skip + } + auto start = clock(); + for (auto &&raw_code : all_raw_codes) { + raw_code.is_horizontal_mirror(); + } + return time_format(start, format) / (double)all_raw_codes.size(); +} + +double Benchmark::vertical_mirror_convert(TIME format) noexcept { + if (!data_ready) { + return -1; // data no ready -> skip + } + auto start = clock(); + for (auto &&raw_code : all_raw_codes) { + raw_code.to_vertical_mirror(); + } + return time_format(start, format) / (double)all_raw_codes.size(); +} + +double Benchmark::horizontal_mirror_convert(TIME format) noexcept { + if (!data_ready) { + return -1; // data no ready -> skip + } + auto start = clock(); + for (auto &&raw_code : all_raw_codes) { + raw_code.to_horizontal_mirror(); + } + return time_format(start, format) / (double)all_raw_codes.size(); +} diff --git a/src/klotski_core/benchmark/benchmark.h b/src/klotski_core/benchmark/benchmark.h index 0e1bc98..9253c35 100644 --- a/src/klotski_core/benchmark/benchmark.h +++ b/src/klotski_core/benchmark/benchmark.h @@ -33,7 +33,6 @@ namespace klotski { }; static void data_preparation() noexcept; static double warm_up(uint64_t count) noexcept; - static double range_flip(TIME format = NS) noexcept; static double all_cases(TIME format = MS) noexcept; @@ -42,26 +41,27 @@ namespace klotski { static double raw_code_check(TIME format = NS) noexcept; static double short_code_check(TIME format = NS) noexcept; static double common_code_check(TIME format = NS) noexcept; - static double raw_code_check_random(TIME format = NS) noexcept; static double short_code_check_random(TIME format = NS) noexcept; static double common_code_check_random(TIME format = NS) noexcept; static double short_code_to_string(TIME format = NS) noexcept; static double short_code_from_string(TIME format = NS) noexcept; - static double common_code_to_string(TIME format = NS) noexcept; static double common_code_from_string(TIME format = NS) noexcept; static double common_code_to_raw_code(TIME format = NS) noexcept; static double raw_code_to_common_code(TIME format = NS) noexcept; - static double common_code_to_short_code(TIME format = NS) noexcept; static double short_code_to_common_code(TIME format = NS) noexcept; - static double common_code_to_short_code_fast(TIME format = NS) noexcept; static double short_code_to_common_code_fast(TIME format = NS) noexcept; + static double vertical_mirror_check(TIME format = NS) noexcept; + static double horizontal_mirror_check(TIME format = NS) noexcept; + static double vertical_mirror_convert(TIME format = NS) noexcept; + static double horizontal_mirror_convert(TIME format = NS) noexcept; + private: static bool data_ready; static std::vector all_raw_codes; diff --git a/src/klotski_core/ffi/tmain.cc b/src/klotski_core/ffi/tmain.cc index 803c873..96a0c03 100644 --- a/src/klotski_core/ffi/tmain.cc +++ b/src/klotski_core/ffi/tmain.cc @@ -67,6 +67,15 @@ void tmain() { std::cout << "short code to common code fast: " << Benchmark::short_code_to_common_code_fast() << "ns" << std::endl; + std::cout << "vertical mirror check: " << + Benchmark::vertical_mirror_check() << "ns" << std::endl; + std::cout << "horizontal mirror check: " << + Benchmark::horizontal_mirror_check() << "ns" << std::endl; + std::cout << "vertical mirror convert: " << + Benchmark::vertical_mirror_convert() << "ns" << std::endl; + std::cout << "horizontal mirror convert: " << + Benchmark::horizontal_mirror_convert() << "ns" << std::endl; + return; std::vector next;