-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathCMakeLists.txt
157 lines (138 loc) · 5.59 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
cmake_minimum_required(VERSION 2.6)
# Set the default CMAKE_BUILD_TYPE to Release.
# This should be done before the project command since the latter can set
# CMAKE_BUILD_TYPE itself (it does so for nmake).
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
endif ()
project(FORMAT_BENCHMARKS)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_CXX_STANDARD 17)
# Workaround a JCC bug in Intel CPUs:
# https://www.intel.com/content/dam/support/us/en/documents/processors/
# mitigations-jump-conditional-code-erratum.pdf
# to get more reliable benchmark results.
set(INTEL FALSE)
if (APPLE)
execute_process(COMMAND sysctl -n machdep.cpu.brand_string
OUTPUT_VARIABLE out)
if (out MATCHES "Intel.*")
set(INTEL TRUE)
endif ()
else ()
file(READ /proc/cpuinfo out)
if (out MATCHES "(.|\n)*GenuineIntel(.|\n)*")
set(INTEL TRUE)
endif ()
endif ()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Ideally we should use -mbranches-within-32B-boundaries but it's not widely
# available so at least align loops to prevent unrelated code changes from
# affecting benchmark results.
set(ALIGN_OPTIONS -mllvm -align-all-blocks=5)
else ()
set(ALIGN_OPTIONS -Wa,-mbranches-within-32B-boundaries)
endif ()
message(STATUS "Align options: ${ALIGN_OPTIONS}")
add_definitions(${ALIGN_OPTIONS})
# Use shared libraries to make comparison with IOStreams and printf
# fair as these use shared libraries too (libstdc++ and libc).
set(BUILD_SHARED_LIBS ON CACHE BOOL
"Build shared library instead of static one")
set(FMT_TEST TRUE CACHE BOOL "Enable fmt tests")
add_subdirectory(fmt)
find_package(Boost)
find_path(FOLLY_INCLUDE_DIR folly/Format.h)
find_library(FOLLY_LIB folly)
if (FOLLY_INCLUDE_DIR AND FOLLY_LIB)
add_definitions(-DHAVE_FOLLY)
set(EXTRA_LIBS ${FOLLY_LIB})
endif ()
find_library(PROFILER_LIB profiler)
find_path(PROFILER_INCLUDE_DIR gperftools/profiler.h)
if (PROFILER_LIB AND PROFILER_INCLUDE_DIR)
include_directories(${PROFILER_INCLUDE_DIR})
set(HAVE_PROFILER TRUE)
endif ()
add_executable(tinyformat_speed_test tinyformat_test.cpp)
target_link_libraries(tinyformat_speed_test fmt ${EXTRA_LIBS})
if (HAVE_PROFILER)
target_link_libraries(tinyformat_speed_test ${PROFILER_LIB})
set(PROFILE_DEFS ";FMT_PROFILE")
endif ()
set_target_properties(tinyformat_speed_test PROPERTIES COMPILE_DEFINITIONS
"SPEED_TEST;HAVE_FORMAT;_SCL_SECURE_NO_WARNINGS;${PROFILE_DEFS}")
if (CPP11_FLAG)
set_target_properties(tinyformat_speed_test
PROPERTIES COMPILE_FLAGS ${CPP11_FLAG})
endif ()
if (WIN32)
add_custom_target(speed-test
COMMAND @echo running speed tests...
COMMAND cd ${CMAKE_CFG_INTDIR}
COMMAND @echo printf timings: start %time%
COMMAND .\\tinyformat_speed_test.exe printf >NUL
COMMAND @echo stop %time%
COMMAND @echo iostreams timings: start %time%
COMMAND .\\tinyformat_speed_test.exe iostreams >NUL
COMMAND @echo stop %time%
COMMAND @echo format timings: start %time%
COMMAND .\\tinyformat_speed_test.exe format >NUL
COMMAND @echo stop %time%
COMMAND @echo tinyformat timings: start %time%
COMMAND .\\tinyformat_speed_test.exe tinyformat >NUL
COMMAND @echo stop %time%
COMMAND @echo boost timings: start %time%
COMMAND .\\tinyformat_speed_test.exe boost >NUL
COMMAND @echo stop %time%
COMMAND @echo stb_sprintf timings: start %time%
COMMAND .\\tinyformat_speed_test.exe stb_sprintf >NUL
COMMAND @echo stop %time%
DEPENDS tinyformat_speed_test)
else()
add_custom_target(speed-test
COMMAND @echo running speed tests...
COMMAND @echo printf timings:
COMMAND @time -p ./tinyformat_speed_test printf > /dev/null
COMMAND @echo iostreams timings:
COMMAND @time -p ./tinyformat_speed_test iostreams > /dev/null
COMMAND @echo format timings:
COMMAND @time -p ./tinyformat_speed_test format > /dev/null
COMMAND @echo fmt::compile timings:
COMMAND @time -p ./tinyformat_speed_test fmt::compile > /dev/null
COMMAND @echo tinyformat timings:
COMMAND @time -p ./tinyformat_speed_test tinyformat > /dev/null
COMMAND @echo boost timings:
COMMAND @time -p ./tinyformat_speed_test boost > /dev/null
COMMAND @echo folly timings:
COMMAND @time -p ./tinyformat_speed_test folly > /dev/null
COMMAND @echo stb_sprintf timings:
COMMAND @time -p ./tinyformat_speed_test stb_sprintf > /dev/null
DEPENDS tinyformat_speed_test)
endif()
add_custom_target(bloat-test
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bloat-test.py -I${Boost_INCLUDE_DIRS}
DEPENDS fmt)
add_custom_target(variadic-test
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/variadic-test.py
\${ARGS} -I${Boost_INCLUDE_DIRS}
DEPENDS fmt)
enable_testing()
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark tests.")
add_subdirectory(benchmark)
add_subdirectory(digits10)
add_executable(vararg-benchmark vararg-benchmark.cc)
target_link_libraries(vararg-benchmark benchmark fmt)
add_executable(int-benchmark src/int-benchmark.cc)
target_link_libraries(int-benchmark benchmark Boost::boost fmt)
target_compile_features(int-benchmark PRIVATE cxx_relaxed_constexpr)
add_executable(locale-benchmark src/locale-benchmark.cc)
target_link_libraries(locale-benchmark benchmark fmt)
add_executable(parse-benchmark src/parse-benchmark.cc)
target_link_libraries(parse-benchmark benchmark fmt)
add_executable(concat-benchmark src/concat-benchmark.cc)
target_link_libraries(concat-benchmark benchmark fmt)
add_executable(find-pow10-benchmark find-pow10-benchmark.cc)
target_link_libraries(find-pow10-benchmark benchmark)
add_subdirectory(src/itoa-benchmark)