Skip to content

Instantly share code, notes, and snippets.

@iaoedsz2008
Last active May 20, 2019 02:30
Show Gist options
  • Save iaoedsz2008/346ad8fc2e0eab751e1b61094e0c9c58 to your computer and use it in GitHub Desktop.
Save iaoedsz2008/346ad8fc2e0eab751e1b61094e0c9c58 to your computer and use it in GitHub Desktop.
c++跨平台高精度定时器
#include <iostream>
#include <chrono>
int main()
{
auto start = std::chrono::high_resolution_clock::now ();
/*
do something...
*/
auto end = std::chrono::high_resolution_clock::now ();
auto duration = std::chrono::duration_cast<std::chrono::microseconds> (end - start);
printf ("总计耗时%f秒\n", (double(duration.count ()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment