|
@ -1,8 +1,23 @@ |
|
|
|
|
|
#include "common.h" |
|
|
#include "benchmark.h" |
|
|
#include "benchmark.h" |
|
|
#include "all_cases.h" |
|
|
#include "all_cases.h" |
|
|
|
|
|
|
|
|
using klotski::Benchmark; |
|
|
using klotski::Benchmark; |
|
|
|
|
|
|
|
|
|
|
|
/// ----------------------------- Benchmark Utils -----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
double Benchmark::range_flip(TIME format) noexcept { |
|
|
|
|
|
uint32_t num = 0; |
|
|
|
|
|
auto start = clock(); |
|
|
|
|
|
for (uint32_t i = 0; i < 0x1'0000'0000 - 0xF; i += 0xE) { |
|
|
|
|
|
Common::range_reverse(i); |
|
|
|
|
|
++num; |
|
|
|
|
|
} |
|
|
|
|
|
return time_format(start, format) / (double)num; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// --------------------------- Benchmark AllCases ----------------------------
|
|
|
|
|
|
|
|
|
double Benchmark::basic_ranges(TIME format) noexcept { |
|
|
double Benchmark::basic_ranges(TIME format) noexcept { |
|
|
if (BasicRanges::status() != BasicRanges::NO_INIT) { |
|
|
if (BasicRanges::status() != BasicRanges::NO_INIT) { |
|
|
return -1; // data already built -> skip
|
|
|
return -1; // data already built -> skip
|
|
@ -22,12 +37,82 @@ double Benchmark::all_cases(TIME format) noexcept { |
|
|
return time_format(start, format); |
|
|
return time_format(start, format); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// -------------------------- Benchmark Code Check ---------------------------
|
|
|
|
|
|
|
|
|
|
|
|
double Benchmark::raw_code_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.valid(); |
|
|
|
|
|
} |
|
|
|
|
|
return time_format(start, format) / (double)all_raw_codes.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
double Benchmark::short_code_check(TIME format) noexcept { |
|
|
|
|
|
if (!data_ready) { |
|
|
|
|
|
return -1; // data no ready -> skip
|
|
|
|
|
|
} |
|
|
|
|
|
auto start = clock(); |
|
|
|
|
|
for (auto &&short_code : all_short_codes) { |
|
|
|
|
|
short_code.valid(); |
|
|
|
|
|
} |
|
|
|
|
|
return time_format(start, format) / (double)all_short_codes.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
double Benchmark::common_code_check(TIME format) noexcept { |
|
|
|
|
|
if (!data_ready) { |
|
|
|
|
|
return -1; // data no ready -> skip
|
|
|
|
|
|
} |
|
|
|
|
|
auto start = clock(); |
|
|
|
|
|
for (auto &&common_code : all_common_codes) { |
|
|
|
|
|
common_code.valid(); |
|
|
|
|
|
} |
|
|
|
|
|
return time_format(start, format) / (double)all_common_codes.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
double Benchmark::raw_code_check_random(TIME format) noexcept { |
|
|
|
|
|
auto random_data = generate_u64_rand(klotski::ALL_CASES_SIZE_SUM); |
|
|
|
|
|
for (auto &&val : random_data) { |
|
|
|
|
|
val &= ~((uint64_t)0b1111 << 60); // clear high 4-bits
|
|
|
|
|
|
} |
|
|
|
|
|
auto start = clock(); |
|
|
|
|
|
for (auto &&raw_code : random_data) { |
|
|
|
|
|
RawCode::check(raw_code); |
|
|
|
|
|
} |
|
|
|
|
|
return time_format(start, format) / (double)random_data.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
double Benchmark::short_code_check_random(TIME format) noexcept { |
|
|
|
|
|
auto random_data = generate_u32_rand(klotski::ALL_CASES_SIZE_SUM); |
|
|
|
|
|
auto start = clock(); |
|
|
|
|
|
for (auto &&short_code : random_data) { |
|
|
|
|
|
ShortCode::check(short_code); |
|
|
|
|
|
} |
|
|
|
|
|
return time_format(start, format) / (double)random_data.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
double Benchmark::common_code_check_random(TIME format) noexcept { |
|
|
|
|
|
auto random_data = generate_u64_rand(klotski::ALL_CASES_SIZE_SUM); |
|
|
|
|
|
for (auto &&val : random_data) { |
|
|
|
|
|
val &= ~((uint64_t)0xFFFFFFF << 36); // clear high 28-bits
|
|
|
|
|
|
} |
|
|
|
|
|
auto start = clock(); |
|
|
|
|
|
for (auto &&common_code : random_data) { |
|
|
|
|
|
CommonCode::check(common_code); |
|
|
|
|
|
} |
|
|
|
|
|
return time_format(start, format) / (double)random_data.size(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// -------------------------- Benchmark Code String --------------------------
|
|
|
|
|
|
|
|
|
double Benchmark::short_code_to_string(TIME format) noexcept { |
|
|
double Benchmark::short_code_to_string(TIME format) noexcept { |
|
|
if (!data_ready) { |
|
|
if (!data_ready) { |
|
|
return -1; // data no ready -> skip
|
|
|
return -1; // data no ready -> skip
|
|
|
} |
|
|
} |
|
|
auto start = clock(); |
|
|
auto start = clock(); |
|
|
for (const auto &short_code : all_short_codes) { |
|
|
for (auto &&short_code : all_short_codes) { |
|
|
short_code.to_string(); |
|
|
short_code.to_string(); |
|
|
} |
|
|
} |
|
|
return time_format(start, format) / (double)all_short_codes.size(); |
|
|
return time_format(start, format) / (double)all_short_codes.size(); |
|
@ -49,7 +134,7 @@ double Benchmark::common_code_to_string(TIME format) noexcept { |
|
|
return -1; // data no ready -> skip
|
|
|
return -1; // data no ready -> skip
|
|
|
} |
|
|
} |
|
|
auto start = clock(); |
|
|
auto start = clock(); |
|
|
for (const auto &common_code : all_common_codes) { |
|
|
for (auto &&common_code : all_common_codes) { |
|
|
common_code.to_string(); |
|
|
common_code.to_string(); |
|
|
} |
|
|
} |
|
|
return time_format(start, format) / (double)all_common_codes.size(); |
|
|
return time_format(start, format) / (double)all_common_codes.size(); |
|
@ -66,6 +151,8 @@ double Benchmark::common_code_from_string(TIME format) noexcept { |
|
|
return time_format(start, format) / (double)all_common_codes_str.size(); |
|
|
return time_format(start, format) / (double)all_common_codes_str.size(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// ------------------------- Benchmark Code Convert --------------------------
|
|
|
|
|
|
|
|
|
double Benchmark::common_code_to_raw_code(TIME format) noexcept { |
|
|
double Benchmark::common_code_to_raw_code(TIME format) noexcept { |
|
|
if (!data_ready) { |
|
|
if (!data_ready) { |
|
|
return -1; // data no ready -> skip
|
|
|
return -1; // data no ready -> skip
|
|
|