C++ chrono使用简单示例
#include <iostream> #include <thread> void customSleep() { std::this_thread::sleep_for(std::chrono::milliseconds(5)); std::this_thread::sleep_for(std::chrono::seconds(5)); } int main() { auto begin = std::chrono::high_resolution_clock::now(); customSleep(); auto diff = std::chrono::high_resolution_clock::now() - begin; long long diffCount = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count(); std::cout << diffCount << endl; return 0; }