提供非中断的时间获取,精确到微秒级
头文件:
#include<windows.h>
函数:
QueryPerformanceCounter(&T) T是一个LARGE_INTEGER结构体,内部是long long数据类型,获取到当前CPU时钟滴答次
QueryPerformanceFrequency(&F) 获取到CPU滴答频率,为1e7
调用:
计算程序运行时间
QueryPerformanceFrequency(&freq); QueryPerformanceCounter(&CountStart); Sleep(100); QueryPerformanceCounter(&CountEnd); T = (double)(CountEnd.QuadPart - CountStart.QuadPart) /(double) freq.QuadPart*1000;
程序计算Sleep(100)即睡眠100ms的精确时间,再调用Sleep前后各取一个滴答,作差除以频率得到单位为s的时间,再乘以1000得到单位为ms的时间,运行结果如下
标签:QueryPerformanceFrequency,高精度,滴答,QueryPerformanceCounter,Sleep,QuadPart,100 From: https://www.cnblogs.com/toriyung/p/17176990.html