Skip to content

Commit e07c062

Browse files
AZero13strega-nil
andauthored
Update google-benchmark to 1.7.0 (#3151)
Co-authored-by: Nicole Mazzuca <[email protected]>
1 parent 569cf9b commit e07c062

File tree

9 files changed

+122
-59
lines changed

9 files changed

+122
-59
lines changed

CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ if(TARGET run-validate)
4242
endif()
4343

4444
option(BUILD_TESTING "Enable testing" ON)
45-
option(STL_BUILD_BENCHMARKING "Enable benchmarking" OFF)
4645
set(VCLIBS_SUFFIX "_oss" CACHE STRING "suffix for built DLL names to avoid conflicts with distributed DLLs")
4746

4847
option(STL_USE_ANALYZE "Pass the /analyze flag to MSVC" OFF)
4948

49+
if(STL_BUILD_BENCHMARKING)
50+
message(WARNING "Due to issues with building google benchmark, "
51+
"STL_BUILD_BENCHMARKING is no longer allowed as part of the STL build. "
52+
"Instead, build the `benchmarks` directory with the STL_BINARY_DIR option.")
53+
endif()
54+
5055
if("${VCLIBS_TARGET_ARCHITECTURE}" MATCHES "^x86$")
5156
set(VCLIBS_TARGET_ARCHITECTURE "x86")
5257
set(VCLIBS_I386_OR_AMD64 "i386")
@@ -115,9 +120,3 @@ if(BUILD_TESTING)
115120
enable_testing()
116121
add_subdirectory(tests)
117122
endif()
118-
if(STL_BUILD_BENCHMARKING)
119-
if(VCLIBS_TARGET_ARCHITECTURE STREQUAL "arm")
120-
message(WARNING "google benchmark does not build on arm32 - this build will likely fail.")
121-
endif()
122-
add_subdirectory(benchmarks)
123-
endif()

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,19 @@ You may also modify an existing benchmark file. We use Google's [Benchmark][gben
413413
so you may find [their documentation][gbenchmark:docs] helpful, and you can also read the existing code
414414
for how _we_ use it.
415415

416-
To run benchmarks, you'll need to configure the STL with the `-DSTL_BUILD_BENCHMARKING=ON` option:
416+
To run benchmarks, you'll need to first build the STL, then build the benchmarks:
417417

418418
```cmd
419-
cmake -B out\bench -S . -G Ninja -DSTL_BUILD_BENCHMARKING=ON
420-
cmake --build out\bench
419+
cmake -B out\x64 -S . -G Ninja
420+
cmake --build out\x64
421+
cmake -B out\benchmark -S benchmarks -G Ninja -DSTL_BINARY_DIR=out\x64
422+
cmake --build out\benchmark
421423
```
422424

423425
You can then run your benchmark with:
424426

425427
```cmd
426-
out\bench\benchmarks\benchmark-<benchmark-name> --benchmark_out=<file> --benchmark_out_format=csv
428+
out\benchmark\benchmark-<benchmark-name> --benchmark_out=<file> --benchmark_out_format=csv
427429
```
428430

429431
And then you can copy this csv file into Excel, or another spreadsheet program. For example:

azure-devops/cmake-configure-build.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ parameters:
1111
- name: buildOutputLocationVar
1212
type: string
1313
default: buildOutputLocation
14-
- name: buildBenchmarking
14+
- name: benchmarkBuildOutputLocationVar
1515
type: string
16-
default: 'ON'
16+
default: benchmarkBuildOutputLocation
1717
- name: cmakeAdditionalFlags
1818
type: string
1919
default: ''
@@ -35,7 +35,6 @@ steps:
3535
cmake ${{ parameters.cmakeAdditionalFlags}} -G Ninja ^
3636
-DCMAKE_CXX_COMPILER=cl ^
3737
-DCMAKE_BUILD_TYPE=Release ^
38-
-DSTL_BUILD_BENCHMARKING=${{ parameters.buildBenchmarking }} ^
3938
-DLIT_FLAGS=$(litFlags) ^
4039
-DSTL_USE_ANALYZE=ON ^
4140
-S $(Build.SourcesDirectory) -B $(${{ parameters.buildOutputLocationVar }})
@@ -49,3 +48,28 @@ steps:
4948
displayName: 'Build the STL'
5049
timeoutInMinutes: 10
5150
env: { TMP: $(tmpDir), TEMP: $(tmpDir) }
51+
- script: |
52+
if exist "$(${{ parameters.benchmarkBuildOutputLocationVar }})" (
53+
rmdir /S /Q "$(${{ parameters.benchmarkBuildOutputLocationVar }})"
54+
)
55+
call "%ProgramFiles%\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat" ^
56+
-host_arch=${{ parameters.hostArch }} -arch=${{ parameters.targetArch }} -no_logo
57+
cmake ${{ parameters.cmakeAdditionalFlags}} -G Ninja ^
58+
-DCMAKE_CXX_COMPILER=cl ^
59+
-DCMAKE_BUILD_TYPE=Release ^
60+
-DLIT_FLAGS=$(litFlags) ^
61+
-DSTL_USE_ANALYZE=ON ^
62+
-DSTL_BINARY_DIR=$(${{ parameters.buildOutputLocationVar }}) ^
63+
-S $(Build.SourcesDirectory)/benchmarks -B $(${{ parameters.benchmarkBuildOutputLocationVar }})
64+
displayName: 'Configure the benchmarks'
65+
timeoutInMinutes: 2
66+
env: { TMP: $(tmpDir), TEMP: $(tmpDir) }
67+
condition: ne('${{ parameters.benchmarkBuildOutputLocationVar }}', '')
68+
- script: |
69+
call "%ProgramFiles%\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat" ^
70+
-host_arch=${{ parameters.hostArch }} -arch=${{ parameters.targetArch }} -no_logo
71+
cmake --build $(${{ parameters.benchmarkBuildOutputLocationVar }})
72+
displayName: 'Build the benchmarks'
73+
timeoutInMinutes: 10
74+
env: { TMP: $(tmpDir), TEMP: $(tmpDir) }
75+
condition: ne('${{ parameters.benchmarkBuildOutputLocationVar }}', '')

azure-devops/cross-build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ parameters:
1212
- name: buildOutputLocationVar
1313
type: string
1414
default: buildOutputLocation
15+
- name: benchmarkBuildOutputLocationVar
16+
type: string
17+
default: benchmarkBuildOutputLocation
1518
- name: numShards
1619
type: number
1720
default: 8
18-
- name: buildBenchmarking
19-
type: string
20-
default: 'ON'
2121
jobs:
2222
- job: '${{ parameters.targetPlatform }}'
2323
variables:
@@ -41,8 +41,8 @@ jobs:
4141
targetPlatform: ${{ parameters.targetPlatform }}
4242
hostArch: ${{ parameters.hostArch }}
4343
targetArch: ${{ parameters.vsDevCmdArch }}
44-
buildBenchmarking: ${{ parameters.buildBenchmarking }}
4544
cmakeAdditionalFlags: '-DTESTS_BUILD_ONLY=ON'
45+
benchmarkBuildOutputLocationVar: ${{ parameters.benchmarkBuildOutputLocationVar }}
4646
- template: run-tests.yml
4747
parameters:
4848
hostArch: ${{ parameters.hostArch }}

azure-devops/native-build-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ parameters:
99
- name: buildOutputLocationVar
1010
type: string
1111
default: buildOutputLocation
12+
- name: benchmarkBuildOutputLocationVar
13+
type: string
14+
default: benchmarkBuildOutputLocation
1215
- name: numShards
1316
type: number
1417
default: 8

azure-pipelines.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
variables:
77
tmpDir: 'D:\Temp'
88
buildOutputLocation: 'D:\build'
9+
benchmarkBuildOutputLocation: 'D:\benchmark'
910

1011
pool:
1112
name: 'StlBuild-2022-10-11T1916-Pool'
@@ -91,7 +92,7 @@ stages:
9192
parameters:
9293
targetPlatform: arm
9394
vsDevCmdArch: arm
94-
buildBenchmarking: 'OFF'
95+
benchmarkBuildOutputLocationVar: ''
9596

9697
- stage: Build_ARM64
9798
dependsOn: Build_And_Test_x64

benchmarks/CMakeLists.txt

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
# Copyright (c) Microsoft Corporation.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4+
cmake_minimum_required(VERSION 3.24)
5+
project(msvc_standard_libraries_benchmarks LANGUAGES CXX)
6+
7+
if(DEFINED STL_BINARY_DIR)
8+
cmake_path(ABSOLUTE_PATH STL_BINARY_DIR
9+
BASE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
10+
NORMALIZE
11+
)
12+
if(NOT EXISTS "${STL_BINARY_DIR}/out")
13+
message(FATAL_ERROR "Invalid STL_BINARY_DIR '${STL_BINARY_DIR}'")
14+
endif()
15+
16+
if(NOT DEFINED VCLIBS_TARGET_ARCHITECTURE)
17+
set(VCLIBS_TARGET_ARCHITECTURE "${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
18+
endif()
19+
20+
string(TOLOWER "${VCLIBS_TARGET_ARCHITECTURE}" VCLIBS_TARGET_ARCHITECTURE)
21+
22+
if("${VCLIBS_TARGET_ARCHITECTURE}" MATCHES "^x86$")
23+
set(VCLIBS_I386_OR_AMD64 "i386")
24+
elseif(VCLIBS_TARGET_ARCHITECTURE MATCHES "^x64$")
25+
set(VCLIBS_I386_OR_AMD64 "amd64")
26+
elseif(VCLIBS_TARGET_ARCHITECTURE MATCHES "^armv7$")
27+
set(VCLIBS_I386_OR_AMD64 "arm")
28+
elseif(VCLIBS_TARGET_ARCHITECTURE MATCHES "^arm64$")
29+
set(VCLIBS_I386_OR_AMD64 "arm64")
30+
else()
31+
message(FATAL_ERROR "Could not determine target architecture: VCLIBS_TARGET_ARCHITECTURE: ${VCLIBS_TARGET_ARCHITECTURE}")
32+
endif()
33+
34+
include_directories(BEFORE "${STL_BINARY_DIR}/out/inc")
35+
link_directories(BEFORE "${STL_BINARY_DIR}/out/lib/${VCLIBS_I386_OR_AMD64}")
36+
else()
37+
message(WARNING "STL_BINARY_DIR not set; benchmarking the globally installed standard library")
38+
endif()
39+
440
set(STL_BENCHMARK_MSVC_RUNTIME_LIBRARY
541
MultiThreaded
642
CACHE STRING "The flavor of the standard library to use; see https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html for more information.")
@@ -32,13 +68,9 @@ endif()
3268
set(BENCHMARK_ENABLE_DOXYGEN OFF)
3369
set(BENCHMARK_ENABLE_INSTALL OFF)
3470
set(BENCHMARK_ENABLE_TESTING OFF)
35-
set(BUILD_SHARED_LIBS OFF)
36-
37-
# TRANSITION, GH-2816: on some machines, librt is found, despite it being a unix-only library
38-
set(HAVE_LIB_RT OFF)
3971

40-
include_directories(BEFORE "${CMAKE_BINARY_DIR}/out/inc")
41-
link_directories(BEFORE "${STL_LIBRARY_OUTPUT_DIRECTORY}")
72+
set(HAVE_GNU_POSIX_REGEX OFF)
73+
set(HAVE_POSIX_REGEX OFF)
4274

4375
add_subdirectory(google-benchmark EXCLUDE_FROM_ALL)
4476

@@ -69,6 +101,8 @@ function(add_benchmark name)
69101
target_compile_features(benchmark-${name} PRIVATE cxx_std_${arg_CXX_STANDARD})
70102
target_include_directories(benchmark-${name} PRIVATE inc)
71103
target_link_libraries(benchmark-${name} PRIVATE benchmark::benchmark)
104+
# TRANSITION, google/benchmark#1450
105+
target_compile_definitions(benchmark-${name} PRIVATE BENCHMARK_STATIC_DEFINE)
72106
endfunction()
73107

74108
add_benchmark(std_copy src/std_copy.cpp)

benchmarks/google-benchmark

Submodule google-benchmark updated 69 files

benchmarks/src/std_copy.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -87,38 +87,38 @@ namespace {
8787
}
8888
} // namespace
8989

90-
BENCHMARK_TEMPLATE1(handwritten_loop, char)->Range(0, 1 << 18);
91-
BENCHMARK_TEMPLATE1(handwritten_loop_n, char)->Range(0, 1 << 18);
92-
BENCHMARK_TEMPLATE1(memcpy_call, char)->Range(0, 1 << 18);
93-
BENCHMARK_TEMPLATE1(std_copy_call, char)->Range(0, 1 << 18);
94-
BENCHMARK_TEMPLATE1(std_copy_n_call, char)->Range(0, 1 << 18);
95-
96-
BENCHMARK_TEMPLATE1(handwritten_loop, aggregate<char>)->Range(0, 1 << 18);
97-
BENCHMARK_TEMPLATE1(handwritten_loop_n, aggregate<char>)->Range(0, 1 << 18);
98-
BENCHMARK_TEMPLATE1(memcpy_call, aggregate<char>)->Range(0, 1 << 18);
99-
BENCHMARK_TEMPLATE1(std_copy_call, aggregate<char>)->Range(0, 1 << 18);
100-
BENCHMARK_TEMPLATE1(std_copy_n_call, aggregate<char>)->Range(0, 1 << 18);
101-
102-
BENCHMARK_TEMPLATE1(handwritten_loop, non_trivial<char>)->Range(0, 1 << 18);
103-
BENCHMARK_TEMPLATE1(handwritten_loop_n, non_trivial<char>)->Range(0, 1 << 18);
104-
BENCHMARK_TEMPLATE1(std_copy_call, non_trivial<char>)->Range(0, 1 << 18);
105-
BENCHMARK_TEMPLATE1(std_copy_n_call, non_trivial<char>)->Range(0, 1 << 18);
106-
107-
BENCHMARK_TEMPLATE1(handwritten_loop, int)->Range(0, 1 << 15);
108-
BENCHMARK_TEMPLATE1(handwritten_loop_n, int)->Range(0, 1 << 15);
109-
BENCHMARK_TEMPLATE1(memcpy_call, int)->Range(0, 1 << 15);
110-
BENCHMARK_TEMPLATE1(std_copy_call, int)->Range(0, 1 << 15);
111-
BENCHMARK_TEMPLATE1(std_copy_n_call, int)->Range(0, 1 << 15);
112-
113-
BENCHMARK_TEMPLATE1(handwritten_loop, aggregate<int>)->Range(0, 1 << 15);
114-
BENCHMARK_TEMPLATE1(handwritten_loop_n, aggregate<int>)->Range(0, 1 << 15);
115-
BENCHMARK_TEMPLATE1(memcpy_call, aggregate<int>)->Range(0, 1 << 15);
116-
BENCHMARK_TEMPLATE1(std_copy_call, aggregate<int>)->Range(0, 1 << 15);
117-
BENCHMARK_TEMPLATE1(std_copy_n_call, aggregate<int>)->Range(0, 1 << 15);
118-
119-
BENCHMARK_TEMPLATE1(handwritten_loop, non_trivial<int>)->Range(0, 1 << 15);
120-
BENCHMARK_TEMPLATE1(handwritten_loop_n, non_trivial<int>)->Range(0, 1 << 15);
121-
BENCHMARK_TEMPLATE1(std_copy_call, non_trivial<int>)->Range(0, 1 << 15);
122-
BENCHMARK_TEMPLATE1(std_copy_n_call, non_trivial<int>)->Range(0, 1 << 15);
90+
BENCHMARK_TEMPLATE(handwritten_loop, char)->Range(0, 1 << 18);
91+
BENCHMARK_TEMPLATE(handwritten_loop_n, char)->Range(0, 1 << 18);
92+
BENCHMARK_TEMPLATE(memcpy_call, char)->Range(0, 1 << 18);
93+
BENCHMARK_TEMPLATE(std_copy_call, char)->Range(0, 1 << 18);
94+
BENCHMARK_TEMPLATE(std_copy_n_call, char)->Range(0, 1 << 18);
95+
96+
BENCHMARK_TEMPLATE(handwritten_loop, aggregate<char>)->Range(0, 1 << 18);
97+
BENCHMARK_TEMPLATE(handwritten_loop_n, aggregate<char>)->Range(0, 1 << 18);
98+
BENCHMARK_TEMPLATE(memcpy_call, aggregate<char>)->Range(0, 1 << 18);
99+
BENCHMARK_TEMPLATE(std_copy_call, aggregate<char>)->Range(0, 1 << 18);
100+
BENCHMARK_TEMPLATE(std_copy_n_call, aggregate<char>)->Range(0, 1 << 18);
101+
102+
BENCHMARK_TEMPLATE(handwritten_loop, non_trivial<char>)->Range(0, 1 << 18);
103+
BENCHMARK_TEMPLATE(handwritten_loop_n, non_trivial<char>)->Range(0, 1 << 18);
104+
BENCHMARK_TEMPLATE(std_copy_call, non_trivial<char>)->Range(0, 1 << 18);
105+
BENCHMARK_TEMPLATE(std_copy_n_call, non_trivial<char>)->Range(0, 1 << 18);
106+
107+
BENCHMARK_TEMPLATE(handwritten_loop, int)->Range(0, 1 << 15);
108+
BENCHMARK_TEMPLATE(handwritten_loop_n, int)->Range(0, 1 << 15);
109+
BENCHMARK_TEMPLATE(memcpy_call, int)->Range(0, 1 << 15);
110+
BENCHMARK_TEMPLATE(std_copy_call, int)->Range(0, 1 << 15);
111+
BENCHMARK_TEMPLATE(std_copy_n_call, int)->Range(0, 1 << 15);
112+
113+
BENCHMARK_TEMPLATE(handwritten_loop, aggregate<int>)->Range(0, 1 << 15);
114+
BENCHMARK_TEMPLATE(handwritten_loop_n, aggregate<int>)->Range(0, 1 << 15);
115+
BENCHMARK_TEMPLATE(memcpy_call, aggregate<int>)->Range(0, 1 << 15);
116+
BENCHMARK_TEMPLATE(std_copy_call, aggregate<int>)->Range(0, 1 << 15);
117+
BENCHMARK_TEMPLATE(std_copy_n_call, aggregate<int>)->Range(0, 1 << 15);
118+
119+
BENCHMARK_TEMPLATE(handwritten_loop, non_trivial<int>)->Range(0, 1 << 15);
120+
BENCHMARK_TEMPLATE(handwritten_loop_n, non_trivial<int>)->Range(0, 1 << 15);
121+
BENCHMARK_TEMPLATE(std_copy_call, non_trivial<int>)->Range(0, 1 << 15);
122+
BENCHMARK_TEMPLATE(std_copy_n_call, non_trivial<int>)->Range(0, 1 << 15);
123123

124124
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)