From 031224a859dbb011dfaa874fa8fa89da9e992a43 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Wed, 25 Jan 2023 14:05:24 +0800 Subject: [PATCH] feat: add _tmain test interface --- src/klotski/CMakeLists.txt | 2 +- src/klotski/ffi/klotski.h | 12 ++++++++++-- src/klotski/ffi/klotski_ffi.cc | 8 ++++---- src/klotski/ffi/tmain.cc | 19 +++++++++++++++++++ src/main.cc | 16 ++++++++++++---- 5 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 src/klotski/ffi/tmain.cc diff --git a/src/klotski/CMakeLists.txt b/src/klotski/CMakeLists.txt index 37406bc..6605b0b 100644 --- a/src/klotski/CMakeLists.txt +++ b/src/klotski/CMakeLists.txt @@ -29,7 +29,7 @@ add_subdirectory(fast_cal) ################################################ #add_library(klotski STATIC klotski_ffi.cc) -add_library(klotski SHARED ffi/klotski_ffi.cc) +add_library(klotski SHARED ffi/klotski_ffi.cc ffi/tmain.cc) ################################################ diff --git a/src/klotski/ffi/klotski.h b/src/klotski/ffi/klotski.h index 22dc2f6..8de902b 100644 --- a/src/klotski/ffi/klotski.h +++ b/src/klotski/ffi/klotski.h @@ -1,4 +1,12 @@ #pragma once -void short_code_speed_up_fast(); -void short_code_speed_up_normal(); +extern "C" { + void _tmain(); +} + +extern "C" { + + void short_code_speed_up(); + void short_code_speed_up_fast(); + +} diff --git a/src/klotski/ffi/klotski_ffi.cc b/src/klotski/ffi/klotski_ffi.cc index 4b4c2f0..a57dbb9 100644 --- a/src/klotski/ffi/klotski_ffi.cc +++ b/src/klotski/ffi/klotski_ffi.cc @@ -2,10 +2,10 @@ #include "short_code.h" -void short_code_speed_up_fast() { - ShortCode::speed_up(ShortCode::FAST); +void short_code_speed_up() { + ShortCode::speed_up(ShortCode::NORMAL); } -void short_code_speed_up_normal() { - ShortCode::speed_up(ShortCode::NORMAL); +void short_code_speed_up_fast() { + ShortCode::speed_up(ShortCode::FAST); } diff --git a/src/klotski/ffi/tmain.cc b/src/klotski/ffi/tmain.cc new file mode 100644 index 0000000..a400622 --- /dev/null +++ b/src/klotski/ffi/tmain.cc @@ -0,0 +1,19 @@ +#include +#include "klotski.h" + +#include "core.h" + +void _tmain() { +// std::cout << "test" << std::endl; + + uint64_t raw_code = 0x0603EDF5CAFFF5E2; + + auto core = Core([](uint64_t code, uint64_t mask) { + return; + }); + + for (uint32_t i = 0; i < 1000000; ++i) { + core.next_cases(raw_code, 0); + } + +} diff --git a/src/main.cc b/src/main.cc index f51feb8..1bf658c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,7 @@ #include +#include "ffi/klotski.h" + //#include "utils/common.h" //#include "all_cases/all_cases.h" // @@ -13,13 +15,13 @@ //#include "graph.h" -#include "benchmark.h" +//#include "benchmark.h" //#include int main() { - std::cout << "start test" << std::endl; +// std::cout << "start test" << std::endl; // std::cout << (uint32_t)Common::check_range(1, Common::range_reverse(0xA9BF0C00)) << std::endl; // @@ -54,9 +56,15 @@ int main() { // std::cout << s << std::endl; // } - Benchmark::basic_ranges(std::cout); +// Benchmark::basic_ranges(std::cout); + + auto start = clock(); + + _tmain(); + + std::cerr << (clock() - start) * 1000000 / CLOCKS_PER_SEC << "us" << std::endl; - std::cout << "end test" << std::endl; +// std::cout << "end test" << std::endl; // BasicRanges::build();