Skip to content

Commit ee74822

Browse files
google-benchmark 1.9.2 and other cleanups (#5370)
1 parent 9699391 commit ee74822

18 files changed

+292
-375
lines changed

NOTICE.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,3 @@ In addition, certain files include the notices provided below.
216216
// shall not be used in advertising or otherwise to promote the sale,
217217
// use or other dealings in these Data Files or Software without prior
218218
// written authorization of the copyright holder.
219-
220-
----------------------
221-
222-
/* Written in 2018 by David Blackman and Sebastiano Vigna ([email protected])
223-
224-
To the extent possible under law, the author has dedicated all copyright
225-
and related and neighboring rights to this software to the public domain
226-
worldwide. This software is distributed without any warranty.
227-
228-
See <http://creativecommons.org/publicdomain/zero/1.0/>. */

benchmarks/CMakeLists.txt

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,15 @@ set_property(CACHE STL_BENCHMARK_MSVC_RUNTIME_LIBRARY
4646
)
4747
set(CMAKE_MSVC_RUNTIME_LIBRARY "${STL_BENCHMARK_MSVC_RUNTIME_LIBRARY}")
4848

49-
set(STL_BENCHMARK_ITERATOR_DEBUG_LEVEL
50-
default
51-
CACHE STRING "What level of iterator debugging to use."
52-
)
53-
set_property(CACHE STL_BENCHMARK_ITERATOR_DEBUG_LEVEL
54-
PROPERTY STRINGS
55-
"default;0;1;2"
56-
)
57-
58-
if(NOT STL_BENCHMARK_ITERATOR_DEBUG_LEVEL STREQUAL "default")
59-
add_compile_definitions("_ITERATOR_DEBUG_LEVEL=${STL_BENCHMARK_ITERATOR_DEBUG_LEVEL}")
60-
endif()
61-
62-
set(CMAKE_BUILD_TYPE RelWithDebInfo)
49+
# Building the benchmarks as Release optimizes them with `/O2 /Ob2`.
50+
# Compiling with `/Zi` and linking with `/DEBUG` below makes profiling possible.
51+
# (RelWithDebInfo would use `/O2 /Ob1 /Zi`.) See GH-4496.
52+
set(CMAKE_BUILD_TYPE Release)
6353

6454
# /utf-8 affects <format>.
65-
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/diagnostics:caret;/W4;/WX;/w14265;/w15038;/w15262;/utf-8;/Zc:preprocessor>")
55+
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/Zi;/nologo;/diagnostics:caret;/W4;/WX;/w14265;/w15038;/w15262;/utf-8;/Zc:preprocessor>")
56+
57+
add_link_options("/DEBUG")
6658

6759
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark/.git")
6860
message(FATAL_ERROR "google-benchmark is not checked out; make sure to run\n git submodule update --init benchmarks/google-benchmark")
@@ -72,15 +64,13 @@ set(BENCHMARK_ENABLE_DOXYGEN OFF)
7264
set(BENCHMARK_ENABLE_INSTALL OFF)
7365
set(BENCHMARK_ENABLE_TESTING OFF)
7466

75-
set(HAVE_GNU_POSIX_REGEX OFF)
76-
set(HAVE_POSIX_REGEX OFF)
77-
7867
add_subdirectory(google-benchmark EXCLUDE_FROM_ALL)
7968

8069
set(benchmark_headers
70+
"inc/lorem.hpp"
71+
"inc/skewed_allocator.hpp"
8172
"inc/udt.hpp"
8273
"inc/utility.hpp"
83-
"inc/xoshiro.hpp"
8474
)
8575

8676
function(add_benchmark name)
@@ -131,7 +121,6 @@ add_benchmark(std_copy src/std_copy.cpp)
131121
add_benchmark(sv_equal src/sv_equal.cpp)
132122
add_benchmark(swap_ranges src/swap_ranges.cpp)
133123
add_benchmark(unique src/unique.cpp)
134-
135-
add_benchmark(vector_bool_copy src/std/containers/sequences/vector.bool/copy/test.cpp)
136-
add_benchmark(vector_bool_copy_n src/std/containers/sequences/vector.bool/copy_n/test.cpp)
137-
add_benchmark(vector_bool_move src/std/containers/sequences/vector.bool/move/test.cpp)
124+
add_benchmark(vector_bool_copy src/vector_bool_copy.cpp)
125+
add_benchmark(vector_bool_copy_n src/vector_bool_copy_n.cpp)
126+
add_benchmark(vector_bool_move src/vector_bool_move.cpp)

benchmarks/google-benchmark

Submodule google-benchmark updated 99 files

benchmarks/inc/utility.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55

66
#include <algorithm>
77
#include <cstddef>
8-
#include <cstdint>
98
#include <random>
109
#include <vector>
1110

12-
#include <xoshiro.hpp>
13-
1411
template <class Contained>
1512
std::vector<Contained> random_vector(size_t n) {
16-
std::random_device rd;
17-
std::uniform_int_distribution<std::uint64_t> id64;
18-
xoshiro256ss prng{id64(rd), id64(rd), id64(rd), id64(rd)};
13+
std::mt19937_64 prng;
1914

2015
std::vector<Contained> res(n);
2116

@@ -25,7 +20,7 @@ std::vector<Contained> random_vector(size_t n) {
2520
// but is insufficient for aggregate<Data> or non_trivial<Data>.
2621
#pragma warning(push)
2722
#pragma warning(disable : 4244) // warning C4244: conversion from 'uint64_t' to 'Data', possible loss of data
28-
std::generate(res.begin(), res.end(), [&prng] { return static_cast<Contained>(prng.next()); });
23+
std::generate(res.begin(), res.end(), [&prng] { return static_cast<Contained>(prng()); });
2924
#pragma warning(pop)
3025

3126
return res;

benchmarks/inc/xoshiro.hpp

Lines changed: 0 additions & 42 deletions
This file was deleted.

benchmarks/src/bitset_from_string.cpp

Lines changed: 68 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -12,89 +12,86 @@
1212

1313
using namespace std;
1414

15-
namespace {
16-
template <size_t N, class charT, size_t Min_length>
17-
auto random_digits_init() {
18-
mt19937_64 rnd{};
19-
uniform_int_distribution<> dis('0', '1');
15+
template <size_t N, class charT, size_t Min_length>
16+
auto random_digits_init() {
17+
mt19937_64 rnd{};
18+
uniform_int_distribution<> dis('0', '1');
2019

21-
constexpr size_t number_of_bitsets = (Min_length + N - 1) / N;
22-
static_assert(number_of_bitsets != 0);
20+
constexpr size_t number_of_bitsets = (Min_length + N - 1) / N;
21+
static_assert(number_of_bitsets != 0);
2322

24-
constexpr size_t actual_size = number_of_bitsets * (N + 1); // +1 for \0
23+
constexpr size_t actual_size = number_of_bitsets * (N + 1); // +1 for \0
2524

26-
array<charT, actual_size> result;
25+
array<charT, actual_size> result;
2726

28-
for (size_t i = 0; i < actual_size; ++i) {
29-
if (i % (N + 1) == N) {
30-
result[i] = charT{'\0'}; // write null terminators
31-
} else {
32-
result[i] = static_cast<charT>(dis(rnd)); // fill random digits
33-
}
27+
for (size_t i = 0; i < actual_size; ++i) {
28+
if (i % (N + 1) == N) {
29+
result[i] = charT{'\0'}; // write null terminators
30+
} else {
31+
result[i] = static_cast<charT>(dis(rnd)); // fill random digits
3432
}
35-
36-
return result;
3733
}
3834

39-
enum class length_type : bool { char_count, null_term };
40-
41-
template <size_t N, class charT>
42-
const auto random_digits = random_digits_init<N, charT, 2048>();
43-
44-
template <length_type Length, size_t N, class charT>
45-
void bitset_from_string(benchmark::State& state) {
46-
const auto& digit_array = random_digits<N, charT>;
47-
for (auto _ : state) {
48-
benchmark::DoNotOptimize(digit_array);
49-
const auto arr_data = digit_array.data();
50-
const auto arr_size = digit_array.size();
51-
for (size_t pos = 0; pos != arr_size; pos += N + 1) {
52-
if constexpr (Length == length_type::char_count) {
53-
bitset<N> bs(arr_data + pos, N);
54-
benchmark::DoNotOptimize(bs);
55-
} else {
56-
bitset<N> bs(arr_data + pos);
57-
benchmark::DoNotOptimize(bs);
58-
}
35+
return result;
36+
}
37+
38+
enum class length_type : bool { char_count, null_term };
39+
40+
template <size_t N, class charT>
41+
const auto random_digits = random_digits_init<N, charT, 2048>();
42+
43+
template <length_type Length, size_t N, class charT>
44+
void bitset_from_string(benchmark::State& state) {
45+
const auto& digit_array = random_digits<N, charT>;
46+
for (auto _ : state) {
47+
benchmark::DoNotOptimize(digit_array);
48+
const auto arr_data = digit_array.data();
49+
const auto arr_size = digit_array.size();
50+
for (size_t pos = 0; pos != arr_size; pos += N + 1) {
51+
if constexpr (Length == length_type::char_count) {
52+
bitset<N> bs(arr_data + pos, N);
53+
benchmark::DoNotOptimize(bs);
54+
} else {
55+
bitset<N> bs(arr_data + pos);
56+
benchmark::DoNotOptimize(bs);
5957
}
6058
}
6159
}
62-
63-
template <class charT, size_t Length>
64-
basic_string<charT> random_digits_contiguous_string_init() {
65-
mt19937_64 rnd{};
66-
uniform_int_distribution<> dis('0', '1');
67-
68-
basic_string<charT> result;
69-
70-
result.resize_and_overwrite(Length, [&](charT* ptr, size_t) {
71-
generate_n(ptr, Length, [&] { return static_cast<charT>(dis(rnd)); });
72-
return Length;
73-
});
74-
75-
return result;
76-
}
77-
78-
template <class charT, size_t Length>
79-
const auto random_digits_contiguous_string = random_digits_contiguous_string_init<charT, Length>();
80-
81-
template <size_t N, class charT>
82-
void bitset_from_stream(benchmark::State& state) {
83-
constexpr size_t string_length = 2048;
84-
constexpr size_t count = string_length / N;
85-
basic_istringstream<charT> stream(random_digits_contiguous_string<charT, string_length>);
86-
bitset<N> bs;
87-
for (auto _ : state) {
88-
benchmark::DoNotOptimize(stream);
89-
for (size_t i = 0; i != count; ++i) {
90-
stream >> bs;
91-
}
92-
benchmark::DoNotOptimize(bs);
93-
stream.seekg(0);
60+
}
61+
62+
template <class charT, size_t Length>
63+
basic_string<charT> random_digits_contiguous_string_init() {
64+
mt19937_64 rnd{};
65+
uniform_int_distribution<> dis('0', '1');
66+
67+
basic_string<charT> result;
68+
69+
result.resize_and_overwrite(Length, [&](charT* ptr, size_t) {
70+
generate_n(ptr, Length, [&] { return static_cast<charT>(dis(rnd)); });
71+
return Length;
72+
});
73+
74+
return result;
75+
}
76+
77+
template <class charT, size_t Length>
78+
const auto random_digits_contiguous_string = random_digits_contiguous_string_init<charT, Length>();
79+
80+
template <size_t N, class charT>
81+
void bitset_from_stream(benchmark::State& state) {
82+
constexpr size_t string_length = 2048;
83+
constexpr size_t count = string_length / N;
84+
basic_istringstream<charT> stream(random_digits_contiguous_string<charT, string_length>);
85+
bitset<N> bs;
86+
for (auto _ : state) {
87+
benchmark::DoNotOptimize(stream);
88+
for (size_t i = 0; i != count; ++i) {
89+
stream >> bs;
9490
}
91+
benchmark::DoNotOptimize(bs);
92+
stream.seekg(0);
9593
}
96-
97-
} // namespace
94+
}
9895

9996
BENCHMARK(bitset_from_string<length_type::char_count, 15, char>);
10097
BENCHMARK(bitset_from_string<length_type::char_count, 16, char>);

benchmarks/src/bitset_to_string.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,43 @@
1212

1313
using namespace std;
1414

15-
namespace {
16-
template <size_t Elems>
17-
auto random_bits_init() {
18-
mt19937_64 rnd{};
19-
array<uint64_t, Elems> arr;
20-
for (auto& d : arr) {
21-
d = rnd();
22-
}
23-
return arr;
15+
template <size_t Elems>
16+
auto random_bits_init() {
17+
mt19937_64 rnd{};
18+
array<uint64_t, Elems> arr;
19+
for (auto& d : arr) {
20+
d = rnd();
2421
}
22+
return arr;
23+
}
2524

26-
template <size_t Elems = 32>
27-
const auto random_bits = random_bits_init<Elems>();
25+
template <size_t Elems = 32>
26+
const auto random_bits = random_bits_init<Elems>();
2827

29-
template <size_t N, class charT>
30-
void BM_bitset_to_string(benchmark::State& state) {
31-
static_assert(N <= 64);
28+
template <size_t N, class charT>
29+
void BM_bitset_to_string(benchmark::State& state) {
30+
static_assert(N <= 64);
3231

33-
for (auto _ : state) {
34-
for (const auto& bits : random_bits<>) {
35-
benchmark::DoNotOptimize(bits);
36-
bitset<N> bs{bits};
37-
benchmark::DoNotOptimize(bs.to_string<charT>());
38-
}
32+
for (auto _ : state) {
33+
for (const auto& bits : random_bits<>) {
34+
benchmark::DoNotOptimize(bits);
35+
bitset<N> bs{bits};
36+
benchmark::DoNotOptimize(bs.to_string<charT>());
3937
}
4038
}
39+
}
4140

42-
template <size_t N, class charT>
43-
void BM_bitset_to_string_large_single(benchmark::State& state) {
44-
static_assert(N % 64 == 0 && N >= 64);
45-
const auto& bitset_data = random_bits<N / 64>;
41+
template <size_t N, class charT>
42+
void BM_bitset_to_string_large_single(benchmark::State& state) {
43+
static_assert(N % 64 == 0 && N >= 64);
44+
const auto& bitset_data = random_bits<N / 64>;
4645

47-
const auto large_bitset = bit_cast<bitset<N>>(bitset_data);
48-
for (auto _ : state) {
49-
benchmark::DoNotOptimize(large_bitset);
50-
benchmark::DoNotOptimize(large_bitset.to_string<charT>());
51-
}
46+
const auto large_bitset = bit_cast<bitset<N>>(bitset_data);
47+
for (auto _ : state) {
48+
benchmark::DoNotOptimize(large_bitset);
49+
benchmark::DoNotOptimize(large_bitset.to_string<charT>());
5250
}
53-
} // namespace
51+
}
5452

5553
BENCHMARK(BM_bitset_to_string<15, char>);
5654
BENCHMARK(BM_bitset_to_string<64, char>);

0 commit comments

Comments
 (0)