mirror of
https://github.com/google/benchmark.git
synced 2025-01-19 00:00:22 +08:00
25acf220a4
Recently the library added a new ranged-for variant of the KeepRunning loop that is much faster. For this reason it should be preferred in all new code. Because a library, its documentation, and its tests should all embody the best practices of using the library, this patch changes all but a few usages of KeepRunning() into for (auto _ : state). The remaining usages in the tests and documentation persist only to document and test behavior that is different between the two formulations. Also note that because the range-for loop requires C++11, the KeepRunning variant has not been deprecated at this time.
29 lines
479 B
C++
29 lines
479 B
C++
|
|
#include "benchmark/benchmark.h"
|
|
|
|
#include <cassert>
|
|
#include <memory>
|
|
|
|
template<typename T>
|
|
class MyFixture : public ::benchmark::Fixture {
|
|
public:
|
|
MyFixture() : data(0) {}
|
|
|
|
T data;
|
|
};
|
|
|
|
BENCHMARK_TEMPLATE_F(MyFixture, Foo, int)(benchmark::State &st) {
|
|
for (auto _ : st) {
|
|
data += 1;
|
|
}
|
|
}
|
|
|
|
BENCHMARK_TEMPLATE_DEFINE_F(MyFixture, Bar, double)(benchmark::State& st) {
|
|
for (auto _ : st) {
|
|
data += 1.0;
|
|
}
|
|
}
|
|
BENCHMARK_REGISTER_F(MyFixture, Bar);
|
|
|
|
BENCHMARK_MAIN()
|