int
main() {
TIMECAPS tc;
if
(timeGetDevCaps(&tc, sizeof(tc))
=
=
TIMERR_NOERROR) {
std::cout <<
"The minimum supported resolution is: "
<< tc.wPeriodMin <<
" ms"
<< std::endl;
std::cout <<
"The maximum supported resolution is: "
<< tc.wPeriodMax <<
" ms"
<< std::endl;
}
else
{
std::cout <<
"Failed to get timer device capabilities."
<< std::endl;
}
/
/
设置系统时钟分辨率为
1ms
MMRESULT result
=
timeBeginPeriod(
1
);
/
/
运行延时代码
std::cout <<
"Starting high-resolution timing test..."
<< std::endl;
auto start
=
std::chrono::high_resolution_clock::now();
for
(
int
i
=
0
; i <
1500
; i
+
+
) {
std::this_thread::sleep_for(std::chrono::milliseconds(
1
));
}
auto end
=
std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> elapsed
=
end
-
start;
std::cout <<
"Elapsed time: "
<< elapsed.count() <<
" ms"
<< std::endl;
/
/
恢复系统时钟分辨率
timeEndPeriod(
1
);
return
0
;
}