Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "benchmark/benchmark.h"
- #include <memory>
- using namespace benchmark;
- void f_movable(State &st, std::unique_ptr<int> pi) {
- for (auto _ : st) {
- for (int i = 0, i1 = *pi; i < i1; ++i) {
- DoNotOptimize(i);
- }
- }
- }
- void f_copyable(State &st, std::shared_ptr<int> pi) {
- for (auto _ : st) {
- for (int i = 0, i1 = *pi; i < i1; ++i) {
- DoNotOptimize(i);
- }
- }
- }
- BENCHMARK_CAPTURE(f_movable, non_copyable, std::make_unique<int>(10)); // This is OK
- BENCHMARK_CAPTURE(f_copyable, copyable, std::make_shared<int>(10)); // This is OK
- int main(int argc, char **argv) {
- ::benchmark::Initialize(&argc, argv);
- if (::benchmark::ReportUnrecognizedArguments(argc, argv))
- return 1;
- auto capture_copyable = [](State &st, std::shared_ptr<int> pi) {
- f_copyable(st, pi);
- };
- auto capture_movable = [](State &st, std::unique_ptr<int> pi) {
- f_movable(st, std::move(pi));
- };
- benchmark::RegisterBenchmark("capture/movable/runtime registration", capture_copyable, std::make_shared<int>(10)); // This is OK
- // The following won't work
- benchmark::RegisterBenchmark("capture/movable/runtime registration", capture_movable, std::make_unique<int>(10));
- ::benchmark::RunSpecifiedBenchmarks();
- }
Add Comment
Please, Sign In to add comment