From b37eef4bf610b0f3abfb1f9b1b7aa90bcec393af Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 20 Jan 2023 01:54:00 +0800 Subject: [PATCH] test: benchmark with diff `FC_MAP_RESERVE` --- src/fast_cal/cal_core.cc | 24 +++++++++++++++ src/fast_cal/fast_cal.h | 2 +- src/main.cc | 63 +++++++++++++++++++++------------------- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/fast_cal/cal_core.cc b/src/fast_cal/cal_core.cc index 1480282..00b59c8 100644 --- a/src/fast_cal/cal_core.cc +++ b/src/fast_cal/cal_core.cc @@ -44,11 +44,35 @@ void FastCal::build() { } } +#include + /// found first matched target RawCode FastCal::target(const match_t &match) { auto core = init(root); + +// std::cout << "-----------------------------------" << std::endl; +// std::cout << "start count: " << cases.bucket_count() << std::endl; + while (!cache.empty()) { if (match(cache.front()->code)) { + +// std::cout << "hashmap size: " << cases.size() << std::endl; +// std::cout << "bucket count: " << cases.bucket_count() << std::endl; +// std::cout << "load factor: " << cases.load_factor() << std::endl; + +// std::vector temp; +// for (uint32_t i = 0; i < cases.bucket_count(); ++i) { +// uint32_t size = cases.bucket_size(i); +// if (size >= temp.size()) { +// temp.resize(size + 1); +// } +// ++temp.at(size); +// } +// for (uint32_t i = 0; i < temp.size(); ++i) { +// std::cout << "size " << i << " -> " << temp[i] << std::endl; +// } + + return RawCode::unsafe_create(cache.front()->code); // match target } core.next_cases(cache.front()->code, cache.front()->mask); diff --git a/src/fast_cal/fast_cal.h b/src/fast_cal/fast_cal.h index 9b77549..955b264 100644 --- a/src/fast_cal/fast_cal.h +++ b/src/fast_cal/fast_cal.h @@ -8,7 +8,7 @@ #include "core.h" #include "raw_code.h" -const uint32_t FC_MAP_RESERVE = 65536; +const uint32_t FC_MAP_RESERVE = 65536 * 8; /// FastCal not found -> return invalid raw code const RawCode FC_NOT_FOUND = RawCode::unsafe_create(0); diff --git a/src/main.cc b/src/main.cc index b42c236..818fc2a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -19,22 +19,22 @@ int main() { // AllCases::build(); -// std::vector test_cases; -// { -// AllCases::build(); -// std::vector all_cases; -// for (uint64_t head = 0; head < 16; ++head) { -// for (const auto &range : AllCases::fetch()[head]) { -// all_cases.emplace_back(head << 32 | range); -// } -// } -// for (uint32_t i = 0; i < 1000; ++i) { -// test_cases.emplace_back( -// RawCode::from_common_code(all_cases.at(i * 29334)) -// ); -// } -// } -// std::cout << "test size -> " << test_cases.size() << std::endl; + std::vector test_cases; + { + AllCases::build(); + std::vector all_cases; + for (uint64_t head = 0; head < 16; ++head) { + for (const auto &range : AllCases::fetch()[head]) { + all_cases.emplace_back(head << 32 | range); + } + } + for (uint32_t i = 0; i < 100; ++i) { + test_cases.emplace_back( + RawCode::from_common_code(all_cases.at(i * 293344)) + ); + } + } + std::cout << "test size -> " << test_cases.size() << std::endl; // std::cout << "wait 3s" << std::endl; @@ -44,25 +44,28 @@ int main() { auto start_time = clock(); -// { -// auto fc = FastCal(RawCode::unsafe_create(0)); -// for (auto code : test_cases) { -// fc.set_root(code); -// fc.solve(); -// } -// } +// auto fc = FastCal(RawCode::from_common_code("1a9bf0c")); +// fc.solve(); + + { + auto fc = FastCal(RawCode::unsafe_create(0)); + for (auto code : test_cases) { + fc.set_root(code); + fc.solve(); + } + } - auto a = Analyse(RawCode::from_common_code("1a9bf0c")); +// auto a = Analyse(RawCode::from_common_code("1a9bf0c")); // a.build(); - auto ret = a.build_until([](uint64_t code) { - return ((code >> (3 * 0xD)) & 0b111) == B_2x2; - }); +// auto ret = a.build_until([](uint64_t code) { +// return ((code >> (3 * 0xD)) & 0b111) == B_2x2; +// }); // for (const auto &r : ret) { // std::cout << r << std::endl; // } - a.backtrack_demo(0x7F87E0E5BFFF492); +// a.backtrack_demo(0x7F87E0E5BFFF492); // a.backtrack_demo(0x1FB1E36F9FFF492); // auto start_time = clock(); @@ -108,8 +111,8 @@ int main() { // std::cerr << (clock() - start_time) / CLOCKS_PER_SEC << "s" << std::endl; -// std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; - std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; + std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; +// std::cerr << (clock() - start_time) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; // std::cout << "complete benchmark" << std::endl;