Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <chrono>
- using namespace std;
- class timer
- {
- chrono::time_point<chrono::high_resolution_clock> a,b;
- public:
- void start(){a = chrono::high_resolution_clock::now();}
- void stop() {b = chrono::high_resolution_clock::now();}
- double value()
- {
- chrono::duration<double> elapsed_seconds = b-a;
- return elapsed_seconds.count();
- }
- void show()
- {
- cout << value()<<" s"<<endl;
- }
- };
- class timer_cumulative
- {
- chrono::time_point<chrono::high_resolution_clock> a,b;
- double cumul_time;
- double elapsed_sec()
- {
- chrono::duration<double> elapsed_seconds = b-a;
- return elapsed_seconds.count();
- }
- public:
- void reset(){cumul_time = 0;}
- timer_cumulative(){reset();}
- // void start(){a = chrono::high_resolution_clock::now(); reset();}
- // void resume() {a = chrono::high_resolution_clock::now();}
- void start(){a = chrono::high_resolution_clock::now();}
- void stop() {b = chrono::high_resolution_clock::now(); cumul_time += elapsed_sec();}
- void show()
- {
- cout << cumul_time<<" s"<<endl;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement