#include <chrono>
int main() {
std::chrono::time_point <std::chrono::system_clock, std::chrono::duration<double, std::milli>> then = std::chrono::high_resolution_clock::now();;
// ... do something ...
std::chrono::time_point <std::chrono::system_clock, std::chrono::duration<double, std::milli>> now = std::chrono::high_resolution_clock::now();;
double elapseTimeInMS = (now - then).count();
return 0;
}
Cách viết khác ngắn hơn:
#include <chrono>
using namespace std;
int main() {
auto then = chrono::high_resolution_clock::now();
// ... do something ...
auto now = chrono::high_resolution_clock::now();
double elapseTimeInMS = chrono::duration<double, milli>(now - then).count();
return 0;
}