Browse Source

feat: add benchmark of ranges

master
Dnomd343 4 weeks ago
parent
commit
41c114e0d3
  1. 3
      src/core/CMakeLists.txt
  2. 66
      src/core/benchmark/ranges.cc
  3. 4
      src/core/ranges/internal/derive.cc

3
src/core/CMakeLists.txt

@ -1,12 +1,11 @@
cmake_minimum_required(VERSION 3.12)
project(klotski_core VERSION 0.0.1 LANGUAGES CXX)
project(klotski_core VERSION 0.0.2 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 23)
set(KLSK_CORE_SRC
ranges/internal/spawn.cc
ranges/internal/ranges.cc
ranges/internal/derive.cc
all_cases/internal/basic_ranges.cc
all_cases/internal/all_cases.cc

66
src/core/benchmark/ranges.cc

@ -4,33 +4,69 @@
#include "ranges/ranges.h"
#include "all_cases/all_cases.h"
using klotski::cases::Ranges;
using klotski::cases::AllCases;
using klotski::cases::BasicRanges;
using klotski::cases::RangesUnion;
static void SpawnRanges(benchmark::State &state) {
// constexpr auto nums = target_nums();
using klotski::group::BLOCK_NUM;
using klotski::cases::ALL_CASES_NUM;
using klotski::cases::BASIC_RANGES_NUM_;
for (auto _ : state) {
Ranges ranges_samples(const size_t num) {
auto &ranges = BasicRanges::instance().fetch();
const size_t part_size = ranges.size() / num;
const size_t offset = part_size / 2;
klotski::cases::Ranges kk {};
kk.reserve(7311921);
Ranges result;
for (size_t i = 0; i < num; ++i) {
result.emplace_back(ranges[i * part_size + offset]);
}
return result;
}
// for (uint32_t type_id = 0; type_id < klotski::cases::TYPE_ID_LIMIT; ++type_id) {
for (auto [n, n_2x1, n_1x1] : klotski::group::BLOCK_NUM) {
kk.spawn(n, n_2x1, n_1x1);
static void CheckRanges(benchmark::State &state) {
auto ranges = ranges_samples(state.range(0));
ranges.reverse();
for (auto _ : state) {
for (const auto range : ranges) {
for (const auto head : RangesUnion::Heads) {
benchmark::DoNotOptimize(Ranges::check(static_cast<int>(head), range));
}
// }
}
}
state.SetItemsProcessed(state.iterations() * state.range(0) * 12);
}
static void RangesReverse(benchmark::State &state) {
static void ReverseRanges(benchmark::State &state) {
auto ranges = BasicRanges::instance().fetch();
for (auto _ : state) {
ranges.reverse();
}
}
static void SpawnRanges(benchmark::State &state) {
for (auto _ : state) {
Ranges ranges {};
ranges.reserve(BASIC_RANGES_NUM_);
for (const auto [n, n_2x1, n_1x1] : BLOCK_NUM) {
ranges.spawn(n, n_2x1, n_1x1);
}
}
}
static void DeriveRanges(benchmark::State &state) {
auto ranges = BasicRanges::instance().fetch();
ranges.reverse();
for (auto _ : state) {
RangesUnion cases;
for (const auto head : RangesUnion::Heads) {
cases.ranges(head).reserve(ALL_CASES_NUM[head]);
ranges.derive(static_cast<int>(head), cases.ranges(head));
}
}
}
static void RangesUnionExport(benchmark::State &state) {
auto &all_cases = AllCases::instance().fetch();
for (auto _ : state) {
@ -77,14 +113,18 @@ static void RangesAt(benchmark::State &state) {
}
}
BENCHMARK(CheckRanges)->Unit(benchmark::kMicrosecond)->Range(16, 256);
// BENCHMARK(ReverseRanges)->Unit(benchmark::kMillisecond);
// BENCHMARK(SpawnRanges)->Unit(benchmark::kMillisecond);
// BENCHMARK(RangesReverse)->Unit(benchmark::kMillisecond);
// BENCHMARK(DeriveRanges)->Unit(benchmark::kMillisecond);
// BENCHMARK(RangesUnionExport)->Unit(benchmark::kMillisecond);
// BENCHMARK(RangesSize);
BENCHMARK(RangesAt);
// BENCHMARK(RangesAt);
BENCHMARK_MAIN();

4
src/core/ranges/internal/derive.cc

@ -1,4 +0,0 @@
// #include "utils/utility.h"
// #include "ranges/ranges.h"
//
// using klotski::cases::Ranges;
Loading…
Cancel
Save