timer.h 607 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef TIMER_H
  2. #define TIMER_H
  3. #include <chrono>
  4. #include <stdio.h>
  5. #include <iostream>
  6. #include <iomanip>
  7. using namespace std;
  8. struct Clock
  9. {
  10. Clock (const char* string){
  11. start_time = chrono::high_resolution_clock::now();
  12. label = string;
  13. }
  14. void get_info(){
  15. chrono::duration<float> seconds = chrono::high_resolution_clock::now() - start_time;
  16. cout<<label;
  17. cout<<fixed<<setprecision(2)<<seconds.count()<<" seconds"<<endl;
  18. }
  19. ~Clock (){}
  20. chrono::high_resolution_clock::time_point start_time;
  21. const char* label;
  22. };
  23. #endif // TIMER_H