catch_measure.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Created by Joachim on 16/04/2019.
  3. * Adapted from donated nonius code.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. // Measure
  9. #ifndef TWOBLUECUBES_CATCH_DETAIL_MEASURE_HPP_INCLUDED
  10. #define TWOBLUECUBES_CATCH_DETAIL_MEASURE_HPP_INCLUDED
  11. #include "../catch_clock.hpp"
  12. #include "catch_complete_invoke.hpp"
  13. #include "catch_timing.hpp"
  14. #include <utility>
  15. namespace Catch {
  16. namespace Benchmark {
  17. namespace Detail {
  18. template <typename Clock, typename Fun, typename... Args>
  19. TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) {
  20. auto start = Clock::now();
  21. auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...);
  22. auto end = Clock::now();
  23. auto delta = end - start;
  24. return { delta, std::forward<decltype(r)>(r), 1 };
  25. }
  26. } // namespace Detail
  27. } // namespace Benchmark
  28. } // namespace Catch
  29. #endif // TWOBLUECUBES_CATCH_DETAIL_MEASURE_HPP_INCLUDED