Browse Source

feat: mirror functions benchmark

master
Dnomd343 1 year ago
parent
commit
2570c5d0f4
  1. 46
      src/klotski_core/benchmark/benchmark.cc
  2. 10
      src/klotski_core/benchmark/benchmark.h
  3. 9
      src/klotski_core/ffi/tmain.cc

46
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();
}

10
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<RawCode> all_raw_codes;

9
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<uint64_t> next;

Loading…
Cancel
Save