浏览代码

add benchmarking framework

tags/v0.0.1
Henry Case 3 年前
父节点
当前提交
56629c53f9
共有 6 个文件被更改,包括 58 次插入13 次删除
  1. +0
    -2
      .astylerc
  2. +0
    -6
      .gitattributes
  3. +1
    -4
      .gitignore
  4. +18
    -1
      CMakeLists.txt
  5. +15
    -0
      test/bench/CMakeLists.txt
  6. +24
    -0
      test/bench/kyber.cc

+ 0
- 2
.astylerc 查看文件

@@ -1,14 +0,0 @@
#--unpad-paren
# disable backup files

+ 0
- 6
.gitattributes 查看文件

@@ -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"

+ 1
- 4
.gitignore 查看文件

@@ -7,7 +7,4 @@ bin/

# Object and library files on Windows
*.lib
*.obj

__pycache__
testcases/
*.obj

+ 18
- 1
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


+ 15
- 0
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
)


+ 24
- 0
test/bench/kyber.cc 查看文件

@@ -0,0 +1,24 @@
#include <array>
#include <stdint.h>
#include <utility>

#include <gtest/gtest.h>
#include <benchmark/benchmark.h>
#include <benchmark/../../src/statistics.h>
#include <benchmark/../../src/cycleclock.h>

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);

正在加载...
取消
保存