add first micro benchmark

This commit is contained in:
Valient Gough 2017-08-06 09:47:33 -07:00
parent 36a4f9c4dd
commit aa533186e3
No known key found for this signature in database
GPG Key ID: 33C65E29813C14DF
3 changed files with 21 additions and 2 deletions

View File

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

View File

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

3
encfs/main_bench.cpp Normal file
View File

@ -0,0 +1,3 @@
#include "benchmark/benchmark.h"
BENCHMARK_MAIN();