结论
windows平台下,精度只能达到毫秒级,不能实现微秒级以下
测试代码
#include <iostream>
#include <thread>
#include <chrono>
using namespace std::chrono;
int main()
{
int testCnt = 10;
auto avg = 0.0;
while (testCnt-- >0) {
auto t1 = steady_clock::now();
for (auto i = 0; i < 10; ++i)
std::this_thread::sleep_for(/*milliseconds(1)*/microseconds(100));
auto t2 = steady_clock::now();
auto diffMs = duration_cast<microseconds>(t2 - t1).count()/1000.0;
avg += diffMs;
std::cout << "delayTime:" << diffMs << " ms"<<std::endl;
}
std::cout << "\navg time:" << avg / 10 << " ms\n" << std::endl;
system("pause");
}
实测图片