Guest User

Untitled

a guest
Jan 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include "benchmark/benchmark.h"
  2. #include <memory>
  3.  
  4. using namespace benchmark;
  5.  
  6. void f_movable(State &st, std::unique_ptr<int> pi) {
  7. for (auto _ : st) {
  8. for (int i = 0, i1 = *pi; i < i1; ++i) {
  9. DoNotOptimize(i);
  10. }
  11. }
  12. }
  13.  
  14. void f_copyable(State &st, std::shared_ptr<int> pi) {
  15. for (auto _ : st) {
  16. for (int i = 0, i1 = *pi; i < i1; ++i) {
  17. DoNotOptimize(i);
  18. }
  19. }
  20. }
  21.  
  22. BENCHMARK_CAPTURE(f_movable, non_copyable, std::make_unique<int>(10)); // This is OK
  23. BENCHMARK_CAPTURE(f_copyable, copyable, std::make_shared<int>(10)); // This is OK
  24.  
  25. int main(int argc, char **argv) {
  26. ::benchmark::Initialize(&argc, argv);
  27. if (::benchmark::ReportUnrecognizedArguments(argc, argv))
  28. return 1;
  29. auto capture_copyable = [](State &st, std::shared_ptr<int> pi) {
  30. f_copyable(st, pi);
  31. };
  32. auto capture_movable = [](State &st, std::unique_ptr<int> pi) {
  33. f_movable(st, std::move(pi));
  34. };
  35. benchmark::RegisterBenchmark("capture/movable/runtime registration", capture_copyable, std::make_shared<int>(10)); // This is OK
  36. // The following won't work
  37. benchmark::RegisterBenchmark("capture/movable/runtime registration", capture_movable, std::make_unique<int>(10));
  38. ::benchmark::RunSpecifiedBenchmarks();
  39. }
Add Comment
Please, Sign In to add comment