You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

measure_time.h 526B

1234567891011121314151617181920
  1. #pragma once
  2. #include <chrono>
  3. #include <iostream>
  4. template<typename Callable>
  5. void measure_time(Callable&& callable) {
  6. using namespace std::chrono;
  7. steady_clock::time_point t_start = steady_clock::now();
  8. callable();
  9. duration<double> time_span = duration_cast<duration<double>>(steady_clock::now() - t_start);
  10. std::cout << "took " << time_span.count() << " seconds\n";
  11. }
  12. template<typename Callable>
  13. void measure_time_with_dry_run(Callable&& callable) {
  14. callable();
  15. measure_time(std::forward<Callable>(callable));
  16. }