mirror of https://github.com/dnomd343/klotski.git
Dnomd343
7 months ago
4 changed files with 66 additions and 31 deletions
@ -0,0 +1,38 @@ |
|||
#include <benchmark/benchmark.h> |
|||
|
|||
#include "group/group.h" |
|||
#include "ranges/ranges.h" |
|||
#include "all_cases/all_cases.h" |
|||
|
|||
using klotski::cases::AllCases; |
|||
|
|||
static void SpawnRanges(benchmark::State &state) { |
|||
// constexpr auto nums = target_nums();
|
|||
|
|||
for (auto _ : state) { |
|||
|
|||
klotski::cases::Ranges kk {}; |
|||
kk.reserve(7311921); |
|||
|
|||
// for (uint32_t type_id = 0; type_id < klotski::cases::TYPE_ID_LIMIT; ++type_id) {
|
|||
for (auto [n, n_2x1, n_1x1] : klotski::cases::BLOCK_NUM) { |
|||
kk.spawn(n, n_2x1, n_1x1); |
|||
} |
|||
// }
|
|||
} |
|||
|
|||
} |
|||
|
|||
static void RangesUnionExport(benchmark::State &state) { |
|||
auto &all_cases = AllCases::instance().fetch(); |
|||
for (auto _ : state) { |
|||
auto codes = all_cases.codes(); |
|||
benchmark::DoNotOptimize(codes.size()); |
|||
} |
|||
} |
|||
|
|||
BENCHMARK(SpawnRanges)->Unit(benchmark::kMillisecond); |
|||
|
|||
// BENCHMARK(RangesUnionExport)->Unit(benchmark::kMillisecond);
|
|||
|
|||
BENCHMARK_MAIN(); |
@ -1,35 +1,35 @@ |
|||
#pragma once |
|||
|
|||
#include "ranges/ranges.h" |
|||
#include "common_code/common_code.h" |
|||
|
|||
using klotski::cases::Ranges; |
|||
using klotski::codec::CommonCode; |
|||
using klotski::cases::RangesUnion; |
|||
|
|||
inline void Ranges::reverse() { |
|||
void Ranges::reverse() { |
|||
for (auto &x : *this) { |
|||
x = range_reverse(x); |
|||
} |
|||
} |
|||
|
|||
inline std::vector<CommonCode> RangesUnion::codes() const { |
|||
std::vector<CommonCode> codes; |
|||
|
|||
codes.reserve(0); // TODO: cal sum
|
|||
|
|||
for (uint64_t head = 0; head < 16; ++head) { |
|||
|
|||
if (head % 4 == 3) { |
|||
continue; |
|||
} |
|||
|
|||
for (auto range : (*this)[head]) { |
|||
auto kk = head << 32 | range; |
|||
codes.emplace_back(CommonCode::unsafe_create(kk)); |
|||
std::vector<CommonCode> RangesUnion::codes() const { |
|||
constexpr auto heads = std::to_array<uint64_t>({ |
|||
0x0, 0x1, 0x2, |
|||
0x4, 0x5, 0x6, |
|||
0x8, 0x9, 0xA, |
|||
0xC, 0xD, 0xE, |
|||
}); |
|||
|
|||
size_type size = 0; |
|||
for (const auto head : heads) { |
|||
size += (*this)[head].size(); |
|||
} |
|||
|
|||
std::vector<CommonCode> codes; |
|||
codes.reserve(size); |
|||
for (const auto head : heads) { |
|||
for (const auto range : (*this)[head]) { |
|||
codes.emplace_back(CommonCode::unsafe_create(head << 32 | range)); |
|||
} |
|||
|
|||
} |
|||
|
|||
return codes; |
|||
} |
|||
|
Loading…
Reference in new issue