Skip to content

Instantly share code, notes, and snippets.

@jniemann66
Created May 21, 2017 02:32
Show Gist options
  • Select an option

  • Save jniemann66/2b9de8dfff2b968b618ccd93b3f52a75 to your computer and use it in GitHub Desktop.

Select an option

Save jniemann66/2b9de8dfff2b968b618ccd93b3f52a75 to your computer and use it in GitHub Desktop.
Really simple RAII millisecond timer
#ifndef _RAIITIMER_H
#define _RAIITIMER_H 1
#include <iostream>
#include <chrono>
class RaiiTimer {
public:
RaiiTimer() {
beginTimer = std::chrono::high_resolution_clock::now();
}
~RaiiTimer() {
endTimer = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTimer - beginTimer).count();
std::cout << "Time=" << duration << " ms" << std::endl;
}
private:
std::chrono::time_point<std::chrono::high_resolution_clock> beginTimer;
std::chrono::time_point<std::chrono::high_resolution_clock> endTimer;
};
#endif // _RAIITIMER_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment