mirror of
https://github.com/google/benchmark.git
synced 2025-03-23 07:30:07 +08:00
Fix examples in user guide using deprecated DoNotOptimize
-API (#1568)
* Update AUTHORS/CONTRIBUTORS * Fix examples with deprecated DoNotOptimize API The const-reference API to DoNotOptimize was deprecated with #1493. Some examples in the user guide are using exactly that deprecated interface. This fixes that by passing non-const lvalues instead. Fixes #1566
This commit is contained in:
parent
23dadfa4a7
commit
f23fedbbf8
1
AUTHORS
1
AUTHORS
@ -43,6 +43,7 @@ Jussi Knuuttila <jussi.knuuttila@gmail.com>
|
||||
Kaito Udagawa <umireon@gmail.com>
|
||||
Kishan Kumar <kumar.kishan@outlook.com>
|
||||
Lei Xu <eddyxu@gmail.com>
|
||||
Marcel Jacobse <mjacobse@uni-bremen.de>
|
||||
Matt Clarkson <mattyclarkson@gmail.com>
|
||||
Maxim Vafin <maxvafin@gmail.com>
|
||||
MongoDB Inc.
|
||||
|
@ -64,6 +64,7 @@ Kai Wolf <kai.wolf@gmail.com>
|
||||
Kaito Udagawa <umireon@gmail.com>
|
||||
Kishan Kumar <kumar.kishan@outlook.com>
|
||||
Lei Xu <eddyxu@gmail.com>
|
||||
Marcel Jacobse <mjacobse@uni-bremen.de>
|
||||
Matt Clarkson <mattyclarkson@gmail.com>
|
||||
Maxim Vafin <maxvafin@gmail.com>
|
||||
Nick Hutchinson <nshutchinson@gmail.com>
|
||||
|
@ -346,7 +346,8 @@ the performance of `std::vector` initialization for uniformly increasing sizes.
|
||||
static void BM_DenseRange(benchmark::State& state) {
|
||||
for(auto _ : state) {
|
||||
std::vector<int> v(state.range(0), state.range(0));
|
||||
benchmark::DoNotOptimize(v.data());
|
||||
auto data = v.data();
|
||||
benchmark::DoNotOptimize(data);
|
||||
benchmark::ClobberMemory();
|
||||
}
|
||||
}
|
||||
@ -492,7 +493,8 @@ static void BM_StringCompare(benchmark::State& state) {
|
||||
std::string s1(state.range(0), '-');
|
||||
std::string s2(state.range(0), '-');
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(s1.compare(s2));
|
||||
auto comparison_result = s1.compare(s2);
|
||||
benchmark::DoNotOptimize(comparison_result);
|
||||
}
|
||||
state.SetComplexityN(state.range(0));
|
||||
}
|
||||
@ -1005,7 +1007,8 @@ static void BM_vector_push_back(benchmark::State& state) {
|
||||
for (auto _ : state) {
|
||||
std::vector<int> v;
|
||||
v.reserve(1);
|
||||
benchmark::DoNotOptimize(v.data()); // Allow v.data() to be clobbered.
|
||||
auto data = v.data(); // Allow v.data() to be clobbered. Pass as non-const
|
||||
benchmark::DoNotOptimize(data); // lvalue to avoid undesired compiler optimizations
|
||||
v.push_back(42);
|
||||
benchmark::ClobberMemory(); // Force 42 to be written to memory.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user