Browse Source

feat: core benchmark framework

master
Dnomd343 6 months ago
parent
commit
6752420d10
  1. 4
      src/core/CMakeLists.txt
  2. 85
      src/core/benchmark/codec.cc
  3. 11
      src/core/main.cc

4
src/core/CMakeLists.txt

@ -33,3 +33,7 @@ add_library(klotski::core ALIAS klotski_core)
# TODO: just for dev testing
add_executable(klotski_core_bin main.cc)
target_link_libraries(klotski_core_bin PRIVATE klotski_core)
add_executable(codec_benchmark benchmark/codec.cc)
target_compile_options(codec_benchmark PRIVATE -fno-rtti -fno-exceptions)
target_link_libraries(codec_benchmark PRIVATE klotski::core benchmark::benchmark_main)

85
src/core/benchmark/codec.cc

@ -0,0 +1,85 @@
#include <iostream>
#include "benchmark/benchmark.h"
#include "all_cases/all_cases.h"
#define private public
#include <group/group.h>
#include "common_code/common_code.h"
using klotski::cases::AllCases;
static std::vector<uint64_t> all_common_codes() {
std::vector<uint64_t> all_codes;
for (uint64_t head = 0; head < 16; ++head) {
for (const auto range : AllCases::instance().fetch()[head]) {
all_codes.emplace_back(head << 32 | range);
}
}
return all_codes;
}
static std::vector<uint64_t> select_codes() {
auto codes = all_common_codes();
return {codes[343], codes[666], codes[114514], codes[35324], codes[123454], codes[76453], codes[93411]};
}
std::vector<uint64_t> samples {
0x00000303F,
0x0000071F0,
0x003339C40,
0x000804340,
0x0034C6D00,
0x00230E0F0,
0x002F371C0,
};
static void Demo(benchmark::State &state) {
// auto samples = select_codes();
//
// for (auto code : samples) {
// auto c = klotski::codec::CommonCode::create(code).value();
// std::cout << c << std::endl;
// }
// std::cout << std::endl;
// samples.clear();
// samples = select_codes();
// samples.emplace_back(0x00000303F);
// samples.emplace_back(0x0000071F0);
// samples.emplace_back(0x003339C40);
// samples.emplace_back(0x000804340);
// samples.emplace_back(0x0034C6D00);
// samples.emplace_back(0x00230E0F0);
// samples.emplace_back(0x002F371C0);
for (auto _ : state) {
for (auto code : samples) {
// auto volatile holder = klotski::codec::CommonCode::string_encode(code);
// auto volatile holder_1 = code + 213;
// auto volatile holder_2 = code + 123;
// auto volatile holder_3 = code + 233;
// auto volatile holder_4 = code + 412;
// auto volatile holder_5 = code + 896;
// auto volatile holder_6 = code + 154;
// auto volatile holder_7 = code + 124;
auto ret = klotski::codec::CommonCode::string_encode(code);
// auto volatile str_1 = ret[0];
// auto volatile str_2 = ret[1];
// auto volatile str_3 = ret[2];
}
}
}
BENCHMARK(Demo);
BENCHMARK_MAIN();

11
src/core/main.cc

@ -1,5 +1,6 @@
#include <thread>
#include <iostream>
#include <format>
#include "core/core.h"
#include "group/group.h"
@ -24,10 +25,12 @@ using klotski::codec::SHORT_CODE_LIMIT;
int main() {
const auto start = clock();
auto kk = GroupUnion::create(123).value();
std::cout << kk.size() << std::endl;
std::cout << kk.group_num() << std::endl;
std::cout << kk.max_group_size() << std::endl;
std::cout << std::format("{:09X}", 0x1A9BF0C00) << std::endl;
// auto kk = GroupUnion::create(123).value();
// std::cout << kk.size() << std::endl;
// std::cout << kk.group_num() << std::endl;
// std::cout << kk.max_group_size() << std::endl;
// auto core = Core([](const uint64_t code, uint64_t) {
// std::cout << RawCode::unsafe_create(code);

Loading…
Cancel
Save