Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix benchmarks in
escaping_benchmark.cc
by properly calling `benchm…
…ark::DoNotOptimize` on both inputs and outputs and by removing the unnecessary and wrong `ABSL_RAW_CHECK` condition (`check != 0`) of `BM_ByteStringFromAscii_Fail` benchmark. Relevant comment: ``` // The DoNotOptimize(...) function can be used to prevent a value or // expression from being optimized away by the compiler. This function is // intended to add little to no overhead. // See: http://stackoverflow.com/questions/28287064 // // The specific guarantees of DoNotOptimize(x) are: // 1) x, and any data it transitively points to, will exist (in a register or // in memory) at the current point in the program. // 2) The optimizer will assume that DoNotOptimize(x) could mutate x or // anything it transitively points to (although it actually doesn't). // // To see this in action: // // void BM_multiply(benchmark::State& state) { // int a = 2; // int b = 4; // for (auto s : state) { // testing::DoNotOptimize(a); // testing::DoNotOptimize(b); // int c = a * b; // testing::DoNotOptimize(c); // } // } // BENCHMARK(BM_multiply); // // Guarantee (2) applied to 'a' and 'b' prevents the compiler lifting the // multiplication outside of the loop. Guarantee (1) applied to 'c' prevents the // compiler from optimizing away 'c' as dead code. ``` To see #1 and #2 in action, see: https://godbolt.org/z/ned1578ve PiperOrigin-RevId: 676588185 Change-Id: I7ed3e4bed8274b54ac7877316f2d82c33d68f00f
- Loading branch information