From a7ee0411163b43dd7d9f5f8cd817da166a29e329 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Mon, 16 Jan 2023 21:43:26 +0800 Subject: [PATCH] feat: ShortCode tiny codec verify --- src/main.cc | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/main.cc b/src/main.cc index c8815ba..21d6185 100644 --- a/src/main.cc +++ b/src/main.cc @@ -8,6 +8,7 @@ #include "fast_cal.h" #include "analyse.h" #include "common.h" +#include "offset/all_cases_offset.h" //#include "core_demo.h" //#include "basic_ranges_demo.h" @@ -51,34 +52,55 @@ // std::cout << std::endl; //} +std::vector all_cases; + +void short_code_verify(uint32_t start, uint32_t end) { + for (uint32_t short_code = start; short_code < end; ++short_code) { + auto common_code = all_cases[short_code]; // correct result + + if (ShortCode(short_code).to_common_code().unwrap() != common_code) { + std::cout << "Error decode: " << ShortCode(short_code) << std::endl; + } + + if (ShortCode(CommonCode(common_code)).unwrap() != short_code) { + std::cout << "Error encode: " << ShortCode(short_code) << std::endl; + } + } + std::cout << "[" << start << ", " << end << ")" << std::endl; +} + int main() { 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); } } - ShortCode::speed_up(ShortCode::FAST); + ShortCode::speed_up(ShortCode::NORMAL); std::cout << "start verify" << std::endl; - auto start_time = clock(); +// auto start_time = clock(); - for (uint32_t short_code = 0; short_code < all_cases.size(); ++short_code) { - auto common_code = all_cases[short_code]; // correct result + std::thread tasks[16]; - if (ShortCode(short_code).to_common_code().unwrap() != common_code) { - std::cout << "error" << std::endl; - } + for (int head = 0; head < 16; ++head) { + uint32_t start = ALL_CASES_OFFSET[head]; + uint32_t end = start + AllCases::fetch()[head].size(); + tasks[head] = std::thread(short_code_verify, start, end); + } - if (ShortCode(CommonCode(common_code)).unwrap() != short_code) { - std::cout << "error" << std::endl; - } + for (auto &t : tasks) { + t.join(); } + std::cout << "verify complete" << std::endl; + return 0; + + + // printf("%p\n", BasicRanges::build); // printf("%p\n", AllCases::build); // @@ -313,7 +335,7 @@ int main() { // std::cout << sizeof(ShortCode) << std::endl; - std::cerr << (clock() - start_time) * 1000 / CLOCKS_PER_SEC << "ms" << 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;