不同延时函数在不同电脑上的对比
PS:是从网上各个帖子中学习的代码,因此代码的格式以及内容有粘贴网上其他大神的代码,如有侵权请告知删除
测试函数:
1 Sleep
2 QueryPerformanceFrequency/QueryPerformanceCounter
3 多媒体定时器
测试方式:
延时10ms,然后打印出当前时间的“时:分:秒.毫秒”
测试结果:
1 Sleep方式代码
#include "stdafx.h"
#include<windows.h>
#include<stdio.h>
#include <chrono>
#include<iostream>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
SYSTEMTIME T;
double time = 0;
while (times < 100000)
{
Sleep(10);
GetLocalTime(&T);
cout << T.wHour << ":" << T.wMinute << ":" << T.wSecond << "." << T.wMilliseconds << endl;
times++;
}
system("Pause");
}
2 QueryPerformance……方式
#include "stdafx.h"
#include