From 2e9dc1f5a7fa96aebbe9c86004732c6eae947817 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 11 Jan 2023 13:37:11 +0800 Subject: [PATCH] feat: all cases fast cal benchmark --- src/fast_cal.cc | 23 ++++++++--------------- src/fast_cal.h | 2 +- src/main.cc | 43 ++++++++++++++++++++++++++++--------------- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/fast_cal.cc b/src/fast_cal.cc index 8a15483..b120889 100644 --- a/src/fast_cal.cc +++ b/src/fast_cal.cc @@ -19,7 +19,7 @@ void add_new_case(uint64_t code, uint64_t mask) { auto exist_case = cal_data.find(code); if (exist_case != cal_data.end()) { // find it // mask update -// std::cout << "match exist case" << std::endl; + return; } @@ -42,11 +42,13 @@ void add_new_case(uint64_t code, uint64_t mask) { } -void fast_cal(uint64_t start_raw_code) { - std::cout << RawCode(start_raw_code).dump_case() << std::endl; +uint32_t fast_cal(uint64_t start_raw_code) { +// std::cout << RawCode(start_raw_code).dump_case() << std::endl; auto core = Core(); + cal_data.empty(); + auto setup = fast_cal_t { .code = start_raw_code, .mask = 0, @@ -55,23 +57,14 @@ void fast_cal(uint64_t start_raw_code) { cal_data[start_raw_code] = setup; cal_temp.emplace(&cal_data[start_raw_code]); -// core.next_step(cal_temp.front()->code, add_new_case); -// cal_temp.pop(); - -// std::cout << "start cal second case" << std::endl; -// std::cout << RawCode(cal_temp.front()->code).dump_case() << std::endl << std::endl; - -// core.next_step(cal_temp.front()->code, add_new_case); -// cal_temp.pop(); - - while (!cal_temp.empty()) { core.next_step(cal_temp.front()->code, add_new_case); cal_temp.pop(); } - std::cout << "size = " << cal_data.size() << std::endl; - std::cout << "queue size = " << cal_temp.size() << std::endl; +// std::cout << "size = " << cal_data.size() << std::endl; +// std::cout << "queue size = " << cal_temp.size() << std::endl; + return cal_data.size(); } diff --git a/src/fast_cal.h b/src/fast_cal.h index e68670a..841afe6 100644 --- a/src/fast_cal.h +++ b/src/fast_cal.h @@ -2,4 +2,4 @@ #include -void fast_cal(uint64_t start_raw_code); +uint32_t fast_cal(uint64_t start_raw_code); diff --git a/src/main.cc b/src/main.cc index 5498e2b..e8b92d8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -160,18 +160,18 @@ int main() { // auto raw_code = RawCode(CommonCode("1A9bf0c")).unwrap(); // c.next_step(raw_code, release); -// std::vector all_cases_raw; -// for (int head = 0; head < 16; ++head) { -// uint64_t prefix = (uint64_t)head << 32; -// for (auto const &range : (*AllCases::fetch())[head]) { -// all_cases_raw.emplace_back( -// RawCode(CommonCode::unsafe_create(prefix | range)).unwrap() -// ); -// } -// } - -// std::cout << "start benchmark" << std::endl; -// auto start_time = clock(); + std::vector all_cases_raw; + for (int head = 0; head < 16; ++head) { + uint64_t prefix = (uint64_t)head << 32; + for (auto const &range : (*AllCases::fetch())[head]) { + all_cases_raw.emplace_back( + RawCode(CommonCode::unsafe_create(prefix | range)).unwrap() + ); + } + } + + std::cout << "start benchmark" << std::endl; + auto start_time = clock(); // auto raw_code = RawCode(CommonCode("4fea134")).unwrap(); // for (int i = 0; i < 100000000; ++i) { @@ -193,10 +193,23 @@ int main() { // } // } -// std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; -// std::cout << "complete benchmark" << std::endl; +// auto raw_code = CommonCode("1a9bf0c").to_raw_code().unwrap(); + + int sum = 0; + for (auto const &raw_code : all_cases_raw) { +// std::cout << RawCode(raw_code).dump_case(); + fast_cal(raw_code); +// std::cout << fast_cal(raw_code) << std::endl; +// std::cout << std::endl; + if (sum % 100000 == 0) { + std::cout << "sum = " << sum << std::endl; + } + ++sum; + + } - fast_cal(CommonCode("1a9bf0c").to_raw_code().unwrap()); + std::cout << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << std::endl; + std::cout << "complete benchmark" << std::endl; return 0; }