2017-10-10 03:10:37 +08:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <memory>
|
|
|
|
|
2021-11-11 00:22:31 +08:00
|
|
|
#include "benchmark/benchmark.h"
|
|
|
|
|
2018-06-01 18:14:19 +08:00
|
|
|
template <typename T>
|
2017-10-10 03:10:37 +08:00
|
|
|
class MyFixture : public ::benchmark::Fixture {
|
2018-06-01 18:14:19 +08:00
|
|
|
public:
|
2017-10-10 03:10:37 +08:00
|
|
|
MyFixture() : data(0) {}
|
|
|
|
|
|
|
|
T data;
|
|
|
|
};
|
|
|
|
|
2018-06-01 18:14:19 +08:00
|
|
|
BENCHMARK_TEMPLATE_F(MyFixture, Foo, int)(benchmark::State& st) {
|
2017-10-18 02:17:02 +08:00
|
|
|
for (auto _ : st) {
|
2017-10-10 03:10:37 +08:00
|
|
|
data += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK_TEMPLATE_DEFINE_F(MyFixture, Bar, double)(benchmark::State& st) {
|
2017-10-18 02:17:02 +08:00
|
|
|
for (auto _ : st) {
|
2017-10-10 03:10:37 +08:00
|
|
|
data += 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BENCHMARK_REGISTER_F(MyFixture, Bar);
|
|
|
|
|
2017-12-04 09:45:07 +08:00
|
|
|
BENCHMARK_MAIN();
|