Browse Source

perf: short code verify

legacy
Dnomd343 2 years 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 kill() { tiny_pool_kill(pool); }
void detach() { tiny_pool_detach(pool); } void detach() { tiny_pool_detach(pool); }
explicit TinyPool(uint32_t size) { pool = tiny_pool_create(size); } explicit TinyPool(uint32_t size) { pool = tiny_pool_create(size); }
// TODO: thread pool destroy
template <typename Func, typename ...Args> template <typename Func, typename ...Args>
auto submit(Func &&func, Args &&...args) -> std::future<decltype(func(args...))> { // submit new task 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; return archive;
} }
TEST(GLOBAL, short_code) { void short_code_verify() {
/// create short code check tasks /// create short code check tasks
auto pool = TinyPool(thread_num()); auto pool = TinyPool(thread_num());
ShortCode::speed_up(ShortCode::NORMAL);
std::vector<std::future<std::vector<uint64_t>>> futures; 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, 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( futures.emplace_back(
pool.submit(short_code_check, range.first, range.second) pool.submit(short_code_check, range.first, range.second)
); );
@ -42,8 +36,6 @@ TEST(GLOBAL, short_code) {
} }
pool.join(); pool.join();
// std::cout << result.size() << std::endl;
/// verify check result /// verify check result
std::vector<uint64_t> all_cases; std::vector<uint64_t> all_cases;
for (uint64_t head = 0; head < 16; ++head) { for (uint64_t head = 0; head < 16; ++head) {
@ -52,5 +44,12 @@ TEST(GLOBAL, short_code) {
} }
} }
EXPECT_EQ(result, all_cases); 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