Browse Source

perf: short code verify

master
Dnomd343 1 year ago
parent
commit
532b1762fa
  1. 1
      test/global/global_utils.h
  2. 17
      test/global/short_code.cc

1
test/global/global_utils.h

@ -24,6 +24,7 @@ public:
void kill() { tiny_pool_kill(pool); }
void detach() { tiny_pool_detach(pool); }
explicit TinyPool(uint32_t size) { pool = tiny_pool_create(size); }
// TODO: thread pool destroy
template <typename Func, typename ...Args>
auto submit(Func &&func, Args &&...args) -> std::future<decltype(func(args...))> { // submit new task

17
test/global/short_code.cc

@ -17,17 +17,11 @@ std::vector<uint64_t> short_code_check(uint32_t start, uint32_t end) {
return archive;
}
TEST(GLOBAL, short_code) {
void short_code_verify() {
/// create short code check tasks
auto pool = TinyPool(thread_num());
ShortCode::speed_up(ShortCode::NORMAL);
std::vector<std::future<std::vector<uint64_t>>> futures;
for (const auto &range : range_split(0, klotski::ALL_CASES_SIZE_SUM, 10000)) {
// for (const auto &range : range_split(0, 80000, 10000)) {
// std::cout << "[" << range.first << ", " << range.second << ")" << std::endl;
futures.emplace_back(
pool.submit(short_code_check, range.first, range.second)
);
@ -42,8 +36,6 @@ TEST(GLOBAL, short_code) {
}
pool.join();
// std::cout << result.size() << std::endl;
/// verify check result
std::vector<uint64_t> all_cases;
for (uint64_t head = 0; head < 16; ++head) {
@ -52,5 +44,12 @@ TEST(GLOBAL, short_code) {
}
}
EXPECT_EQ(result, all_cases);
}
TEST(GLOBAL, short_code) {
ShortCode::speed_up(ShortCode::NORMAL); // normal mode
short_code_verify();
ShortCode::speed_up(ShortCode::FAST); // fast mode
short_code_verify();
}

Loading…
Cancel
Save