1. 程式人生 > >c++11計時:chrono

c++11計時:chrono

#include <chrono>
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();

某段程式碼

std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> time_used = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1)*1000;
std::cout << "time:" << time_used.count() << " ms" << std::endl;