diff --git a/.astylerc b/.astylerc deleted file mode 100644 index 21047d05..00000000 --- a/.astylerc +++ /dev/null @@ -1,14 +0,0 @@ ---style=google ---indent=spaces ---indent-preproc-define ---indent-preproc-cond ---pad-oper ---pad-comma ---pad-header -#--unpad-paren ---align-pointer=name ---add-braces ---convert-tabs ---mode=c -# disable backup files ---suffix=none diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 78b4644b..00000000 --- a/.gitattributes +++ /dev/null @@ -1,6 +0,0 @@ -* text=auto -*.[ch] text whitespacestrict -*.yaml text whitespacestrict -Makefile text whitespace="tabwidth=4,-tab-in-indent,indent-with-non-tab" - -[attr]whitespacestrict whitespace="trailing-space,tab-in-indent,space-before-tab,tabwidth=4" diff --git a/.gitignore b/.gitignore index 8c0e3e45..3c611a83 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,4 @@ bin/ # Object and library files on Windows *.lib -*.obj - -__pycache__ -testcases/ +*.obj \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee78b71..e7bf41f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,21 @@ else() message(FATAL_ERROR "Unknown processor:" ${CMAKE_SYSTEM_PROCESSOR}) endif() -add_subdirectory(3rd/gtest) +add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/gtest) +if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug") + # settings below are required by benchmark library + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) + # Target for benchmark - it also builds gtest library + set(BENCHMARK_ENABLE_GTEST_TESTS ON CACHE BOOL "Enable testing of the benchmark library." FORCE) + set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark tests" FORCE) + set(GOOGLETEST_PATH "${CMAKE_SOURCE_DIR}/3rd/gtest" CACHE PATH "Path to the gtest sources" FORCE) + #if (NOT MACOSX) + # set(BENCHMARK_ENABLE_LTO ON CACHE BOOL "Enable link time optim" FORCE) + #endif() + set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE) + add_subdirectory(${CMAKE_SOURCE_DIR}/3rd/gbench) +endif() + # Arch settings @@ -268,6 +282,9 @@ target_include_directories( ${CMAKE_SOURCE_DIR}) +if(NOT CMAKE_BUILD_TYPE_LOWER STREQUAL "debug") +add_subdirectory(test/bench) +endif() install(TARGETS pqc pqc_s PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ GROUP_WRITE WORLD_READ WORLD_WRITE diff --git a/test/bench/CMakeLists.txt b/test/bench/CMakeLists.txt new file mode 100644 index 00000000..64fa5ec0 --- /dev/null +++ b/test/bench/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.13) + +add_executable( + bench + kyber.cc +) + +target_link_libraries( + bench + + pqc + benchmark + benchmark_main +) + diff --git a/test/bench/kyber.cc b/test/bench/kyber.cc new file mode 100644 index 00000000..06605144 --- /dev/null +++ b/test/bench/kyber.cc @@ -0,0 +1,24 @@ +#include +#include +#include + +#include +#include +#include +#include + +auto cpucycle = [](benchmark::State &st, int64_t cycles) { + st.counters["CPU cycles: mean"] = benchmark::Counter( + cycles, benchmark::Counter::kAvgIterations | benchmark::Counter::kResultNoFormat); +}; + +static void BenchKyberMatK2(benchmark::State &st) { + int64_t t, total = 0; + for (auto _ : st) { + t = benchmark::cycleclock::Now(); + total += benchmark::cycleclock::Now() - t; + } + cpucycle(st, total); +} + +BENCHMARK(BenchKyberMatK2);