chrono--高精度计时
在C++中使用chrono标准库进行高精度计时。示例如下:
1 #include<iostream> 2 #include<ctime> 3 #include<ratio> 4 #include<chrono> 5 6 int main(int argc, char* argv[]) 7 { 8 using namespace std::chrono; 9 high_resolution_clock::time_point t = high_resolution_clock::now(); 10 11 std::cout << "printing out 1000 stars...\n"; 12 for (int i = 0; i < 1000; i++) 13 { 14 std::cout << "*"; 15 16 } 17 std::cout << std::endl; 18 19 high_resolution_clock::time_point t2 = high_resolution_clock::now(); 20 duration<double> time_span = duration_cast<duration<double>>(t2 - t); 21 22 std::cout << "It tooks me " << time_span.count() << "seconds"; 23 std::cout << std::endl; 24 25 return 0; 26 }
参考: http://www.cplusplus.com/reference/chrono/high_resolution_clock/now/