Skip to content

Instantly share code, notes, and snippets.

@quiye
Created June 13, 2020 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quiye/e12661134f2301c82bbe18114d08ff87 to your computer and use it in GitHub Desktop.
Save quiye/e12661134f2301c82bbe18114d08ff87 to your computer and use it in GitHub Desktop.
simple stop watch (timer)
class stopWatch {
private:
decltype(std::chrono::high_resolution_clock::now()) start = std::chrono::high_resolution_clock::now();
public:
~stopWatch() {
const auto finish = std::chrono::high_resolution_clock::now();
const auto durationMilliSeconds = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();
std::cout << durationMilliSeconds << " ms" << std::endl;
}
};
@quiye
Copy link
Author

quiye commented Jun 13, 2020

usage

int main() {
  {
    stopWatch t;
    // do some ...
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment