C++计时器
来源:互联网 发布:网络安全技术身份认证 编辑:程序博客网 时间:2024/05/29 12:22
/Windows系统下可以用 time(),clock(),timeGetTime(),GetTickCount(),QueryPerformanceCounter()来对一段程序代码进行计时#include <stdio.h>#include <windows.h>#include <time.h> //time_t time() clock_t clock() #include <Mmsystem.h> //timeGetTime() #pragma comment(lib, "Winmm.lib") //timeGetTime() //使用方法:将Sleep()函数换成需要测试运行时间的函数即可。int main(){ //用time()来计时,以秒为单位 time_t timeBegin, timeEnd; timeBegin = time(NULL); Sleep(1000); timeEnd = time(NULL); printf("%d\n", timeEnd - timeBegin); //用clock()来计时,以毫秒为单位 clock_t clockBegin, clockEnd; clockBegin = clock(); Sleep(800); clockEnd = clock(); printf("%d\n", clockEnd - clockBegin); //用timeGetTime()来计时,以毫秒为单位 DWORD dwBegin, dwEnd; dwBegin = timeGetTime(); Sleep(800); dwEnd = timeGetTime(); printf("%d\n", dwEnd - dwBegin); //用GetTickCount()来计时,以毫秒为单位 DWORD dwGTCBegin, dwGTCEnd; dwGTCBegin = GetTickCount(); Sleep(800); dwGTCEnd = GetTickCount(); printf("%d\n", dwGTCEnd - dwGTCBegin); //用QueryPerformanceCounter()来计时,以微秒为单位 LARGE_INTEGER large_interger; double dff; __int64 c1, c2; QueryPerformanceFrequency(&large_interger); dff = large_interger.QuadPart; QueryPerformanceCounter(&large_interger); c1 = large_interger.QuadPart; Sleep(800); QueryPerformanceCounter(&large_interger); c2 = large_interger.QuadPart; printf("本机高精度计时器频率%lf\n", dff); printf("第一次计时器值%I64d\n第二次计时器值%I64d\n计时器差%I64d\n", c1, c2, c2 - c1); printf("计时%lf毫秒\n\n", (c2 - c1) * 1000 / dff); return 0;}
0 0
- C ++ 计时器
- c、c#---计时器
- [C#] Timer计时器
- linux c 语言 计时器
- [C#] Timer计时器
- C语音简单计时器
- C++-1、计时器
- 3.5 watchdog.c:计时器
- C 计时器大全
- Windows/Linux高精度计时器(C++)
- C/C++高精度计时器类
- C语言计时器的使用
- Windows/Linux高精度计时器(C++)
- 【c#】控制台程序编写计时器
- C#计时器精度的探究
- 计时器
- 计时器
- 计时器
- 机器学习基础(三十九)—— scikit-learn 的使用
- 第1周 C语言及程序设计初步 例程-4 for语句案例
- codeforce 659E (dfs 水~)
- 两个嵌套的div margin-top无效的解决办法
- 联系人数据库contacts2.db介绍
- C++计时器
- mybatis中使用foreach构造多like查询及批量插入
- Asynctask解析
- Eclipse反编译插件安装
- 匈牙利算法
- 解析spring的IOC、AOP?
- 贪心算法 problem I(1009)
- 【poj 3468】A Simple Problem with Integers 题意&题解&代码(C++)
- C++ COM