From 073789c76726e2ce6c26a7acaa766aa6ba85320a Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Tue, 7 May 2019 03:10:20 +0700 Subject: [PATCH] add dummy benchmark project --- CMakeLists.txt | 7 ++++++- unbench/CMakeLists.txt | 24 ++++++++++++++++++++++++ unbench/flat_map_bench.cpp | 21 +++++++++++++++++++++ unbench/flat_set_bench.cpp | 21 +++++++++++++++++++++ untests/CMakeLists.txt | 6 ++++-- 5 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 unbench/CMakeLists.txt create mode 100644 unbench/flat_map_bench.cpp create mode 100644 unbench/flat_set_bench.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 94c0bc8..c62b32d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,14 @@ project(flat.hpp) add_library(${PROJECT_NAME} INTERFACE) target_include_directories(${PROJECT_NAME} INTERFACE headers) target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_14) -add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) if(BUILD_AS_STANDALONE) + option(BUILD_WITH_UNBENCH "Build with benchmarks" OFF) + if(BUILD_WITH_UNBENCH) + enable_testing() + add_subdirectory(unbench) + endif() + option(BUILD_WITH_UNTESTS "Build with unit tests" ON) if(BUILD_WITH_UNTESTS) enable_testing() diff --git a/unbench/CMakeLists.txt b/unbench/CMakeLists.txt new file mode 100644 index 0000000..b077be1 --- /dev/null +++ b/unbench/CMakeLists.txt @@ -0,0 +1,24 @@ +# 3.11 version is required for `FetchContent` +cmake_minimum_required(VERSION 3.11 FATAL_ERROR) + +project(flat.hpp.unbench) + +set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) + +include(FetchContent) +FetchContent_Declare( + gbench + GIT_REPOSITORY https://github.com/google/benchmark) + +FetchContent_GetProperties(gbench) +if(NOT gbench_POPULATED) + FetchContent_Populate(gbench) + add_subdirectory(${gbench_SOURCE_DIR} ${gbench_BINARY_DIR}) +endif() + +file(GLOB UNBENCH_SOURCES "*.cpp" "*.hpp") +add_executable(${PROJECT_NAME} ${UNBENCH_SOURCES}) +target_link_libraries(${PROJECT_NAME} + benchmark_main + flat.hpp) +add_test(${PROJECT_NAME} ${PROJECT_NAME}) diff --git a/unbench/flat_map_bench.cpp b/unbench/flat_map_bench.cpp new file mode 100644 index 0000000..c3c9efe --- /dev/null +++ b/unbench/flat_map_bench.cpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/flat.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include + +#include +using namespace flat_hpp; + +namespace +{ + void flat_map_default_ctor(benchmark::State& state) { + for ( auto _ : state ) { + flat_map s0; + } + } +} + +BENCHMARK(flat_map_default_ctor); diff --git a/unbench/flat_set_bench.cpp b/unbench/flat_set_bench.cpp new file mode 100644 index 0000000..fb1232b --- /dev/null +++ b/unbench/flat_set_bench.cpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * This file is part of the "https://github.com/blackmatov/flat.hpp" + * For conditions of distribution and use, see copyright notice in LICENSE.md + * Copyright (C) 2019, by Matvey Cherevko (blackmatov@gmail.com) + ******************************************************************************/ + +#include + +#include +using namespace flat_hpp; + +namespace +{ + void flat_set_default_ctor(benchmark::State& state) { + for ( auto _ : state ) { + flat_set s0; + } + } +} + +BENCHMARK(flat_set_default_ctor); diff --git a/untests/CMakeLists.txt b/untests/CMakeLists.txt index 157b777..735fbe1 100644 --- a/untests/CMakeLists.txt +++ b/untests/CMakeLists.txt @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.11 FATAL_ERROR) project(flat.hpp.untests) +set(CATCH_BUILD_TESTING OFF CACHE BOOL "" FORCE) + include(FetchContent) FetchContent_Declare( catch2 @@ -17,6 +19,6 @@ endif() file(GLOB UNTESTS_SOURCES "*.cpp" "*.hpp") add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES}) target_link_libraries(${PROJECT_NAME} - Catch2::Catch2 - flat.hpp::flat.hpp) + Catch2 + flat.hpp) add_test(${PROJECT_NAME} ${PROJECT_NAME})