gpt4 book ai didi

c++ - C++11 中的定时器,带 chrono : from nanoseconds to milliseconds

转载 作者:太空狗 更新时间:2023-10-29 20:04:24 25 4
gpt4 key购买 nike

我想知道函数花费的毫秒数。我正在像这样使用 chrono:

chrono::system_clock::time_point start = chrono::high_resolution_clock::now();

// big_function ...

cout << "Function took: " << chrono::nanoseconds(chrono::high_resolution_clock::now() - start).count() << "nanosec" << endl;

打印:“Function took: 32423212131321 nanosec”
有什么方法可以打印毫秒而不是纳秒?

最佳答案

您可以使用duration_cast

chrono::duration_cast<chrono::milliseconds>
(chrono::high_resolution_clock::now() - start).count()

关于c++ - C++11 中的定时器,带 chrono : from nanoseconds to milliseconds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20215171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com