From aa533186e313c9d7f4f63464130409a215eac2bb Mon Sep 17 00:00:00 2001 From: Valient Gough Date: Sun, 6 Aug 2017 09:47:33 -0700 Subject: [PATCH] add first micro benchmark --- CMakeLists.txt | 6 ++++-- encfs/MemoryPool_bench.cpp | 14 ++++++++++++++ encfs/main_bench.cpp | 3 +++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 encfs/MemoryPool_bench.cpp create mode 100644 encfs/main_bench.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ef473a..1fe770f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,12 +288,14 @@ if (BUILD_UNIT_TESTS) set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "benchmark tests") add_subdirectory(${GOOGLEBENCH_DIR}) link_directories(${CMAKE_BINARY_DIR}/${GOOGLEBENCH_DIR}) - set(GOOGLEBENCH_LIBRARIES benchmark) file(GLOB_RECURSE TEST_SOURCES "encfs/*_test.cpp") - add_executable (unittests ${TEST_SOURCES}) target_link_libraries(unittests gtest gtest_main encfs) + + file(GLOB_RECURSE BENCH_SOURCES "encfs/*_bench.cpp") + add_executable (benchmarks ${BENCH_SOURCES}) + target_link_libraries(benchmarks benchmark encfs) endif () add_custom_target(tests COMMAND ${CMAKE_CURRENT_LIST_DIR}/test.sh) diff --git a/encfs/MemoryPool_bench.cpp b/encfs/MemoryPool_bench.cpp new file mode 100644 index 0000000..9326e43 --- /dev/null +++ b/encfs/MemoryPool_bench.cpp @@ -0,0 +1,14 @@ +#include "benchmark/benchmark.h" + +#include "MemoryPool.h" + +using namespace encfs; + +static void BM_MemPoolAllocate(benchmark::State& state) { + while (state.KeepRunning()) { + auto block = MemoryPool::allocate(1024); + MemoryPool::release(block); + } +} +// Register the function as a benchmark +BENCHMARK(BM_MemPoolAllocate); diff --git a/encfs/main_bench.cpp b/encfs/main_bench.cpp new file mode 100644 index 0000000..a78145f --- /dev/null +++ b/encfs/main_bench.cpp @@ -0,0 +1,3 @@ +#include "benchmark/benchmark.h" + +BENCHMARK_MAIN(); \ No newline at end of file