xlnt/benchmarks/CMakeLists.txt
JCrawfy 0adb8a69b1 add micro benchmarking project, setup number parsing benchmark
relating to previous work https://github.com/tfussell/xlnt/issues/422
Results are matching what was observed at the time ^^ was being worked on
std::from_chars is included as the target to beat, but since only MSVC has it for floating point it's not
hugely useful yet

uniform real distribution is probably a horrible choice, and it might be good to randomise the number
of sf in each string also (currently the y all end up at max length)

Run on (4 X 3500 MHz CPU s)
CPU Caches:
  L1 Data 32K (x4)
  L1 Instruction 32K (x4)
  L2 Unified 262K (x4)
  L3 Unified 6291K (x1)
----------------------------------------------------------------------------------------------------------
Benchmark                                                                Time             CPU   Iterations
----------------------------------------------------------------------------------------------------------
RandFloats/double_from_string_sstream                                  804 ns          820 ns       896000
RandFloats/double_from_string_strtod                                   163 ns          162 ns      5973333
RandFloats/double_from_string_strtod_fixed                             175 ns          172 ns      5352107
RandFloats/double_from_string_strtod_fixed_const_ref                   150 ns          152 ns      5352107
RandFloats/double_from_string_std_from_chars                          87.1 ns         88.3 ns      9557333
RandFloatsComma/double_from_string_strtod_fixed_comma_ref              172 ns          173 ns      5146257
RandFloatsComma/double_from_string_strtod_fixed_comma_const_ref        180 ns          175 ns      5352107
2020-02-29 22:11:31 +13:00

48 lines
1.6 KiB
CMake

cmake_minimum_required(VERSION 3.1)
project(xlnt.benchmarks)
# Require C++11 compiler
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(NOT COMBINED_PROJECT)
# Include xlnt library
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../source ${CMAKE_CURRENT_BINARY_DIR}/source)
endif()
if(STATIC_CRT)
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/ucm.cmake)
ucm_set_runtime(STATIC)
endif()
set(XLNT_BENCHMARK_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
file(GLOB BENCHMARK_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
foreach(BENCHMARK_SOURCE IN ITEMS ${BENCHMARK_SOURCES})
# Convert <name>.cpp to benchmark-<name>
get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE)
set(BENCHMARK_EXECUTABLE benchmark-${BENCHMARK_NAME})
add_executable(${BENCHMARK_EXECUTABLE} ${BENCHMARK_SOURCE})
target_link_libraries(${BENCHMARK_EXECUTABLE} PRIVATE xlnt)
# Need to use some test helpers
target_include_directories(${BENCHMARK_EXECUTABLE}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../tests)
target_compile_definitions(${BENCHMARK_EXECUTABLE}
PRIVATE XLNT_BENCHMARK_DATA_DIR=${XLNT_BENCHMARK_DATA_DIR})
if(MSVC AND NOT STATIC)
# Copy xlnt DLL into benchmarks directory
add_custom_command(TARGET ${BENCHMARK_EXECUTABLE} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
$<TARGET_FILE:xlnt>
$<TARGET_FILE_DIR:${BENCHMARK_EXECUTABLE}>)
endif()
endforeach()
option(XLNT_MICROBENCH_ENABLED "Enable small benchmarks typically used for development" OFF)
if (XLNT_MICROBENCH_ENABLED)
add_subdirectory(microbenchmarks)
endif()