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;
}

 

posted @ 2021-05-17 15:51  纸船  阅读(427)  评论(0编辑  收藏  举报