C ++将纳秒转换为毫秒

问题描述 投票:-1回答:1

我正在尝试监视一段代码在纳秒和毫秒内运行所花费的时间,并且我正在运行纳秒,现在我正在尝试进行duration_cast来将纳秒转换为毫秒,但它没有用仅输出0,而持续时间的代码似乎没有运行。

// Get start time
const auto startTime = std::chrono::high_resolution_clock::now();

 // function here

// Get end time
const auto endTime = std::chrono::high_resolution_clock::now();
const auto durationNS = (endTime - startTime).count();
const auto int_ms = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
const auto durationMS = int_ms.count();

在底部,您可以看到我正在进行的持续时间转换,但它没有任何建议吗?

c++ chrono
1个回答
0
投票
const auto endTime = std::chrono::high_resolution_clock::now(); const auto durationNS = (endTime - startTime).count(); std::chrono::duration<double, std::milli> fp_ms = endTime - startTime; const auto durationMS = fp_ms.count();
以上代码有效。    
© www.soinside.com 2019 - 2024. All rights reserved.