c语言计算时间方法---clock-GetTickCount-QueryPerformanceCounter
2014-04-02 21:35
453 查看
1、头文件time.h,函数clock()
2、GetTickCount函数
3、QueryPerformanceCounter
#include "stdafx.h" #include <time.h> #include <stdlib.h> #include <math.h> int main(void) { int i,sum=0; clock_t start,finish; start=clock(); for(i=1;i<10000000;i++) { sum+=sqrt((float)i); } finish=clock(); printf("The time is %dms.\n",finish-start); printf("The time is %ds\n",(finish-start)/1000); system("pause"); return 0; }
2、GetTickCount函数
#include <stdio.h> #include <windows.h> int main(void) { double t0,t1; int i; t0=GetTickCount(); Sleep(200); t1=GetTickCount(); printf("----%fms",t1-t0); getchar(); return 0; }
3、QueryPerformanceCounter
#include <stdio.h> #include <windows.h> int main(void) { LARGE_INTEGER freq, freqcnt; double dcnt, cnt1, cnt2; QueryPerformanceFrequency(&freq); dcnt=freq.QuadPart; QueryPerformanceCounter(&freqcnt); cnt1=freqcnt.QuadPart; Sleep(1000); QueryPerformanceCounter(&freqcnt); cnt2=freqcnt.QuadPart; printf("----%fms",(cnt1-cnt2)/dcnt*1000); getchar(); return 0; }
相关文章推荐
- 计算程序运行时间的函数Sleep,clock,GetTickCount,QueryPerformanceCounter
- 时间的函数,sleep,clock,gettickcount,QueryPerformanceCounter(转)
- 时间的函数,sleep,clock,gettickcount,QueryPerformanceCounter
- 时间的函数Sleep,clock,GetTickCount,QueryPerformanceCounter
- 时间的函数,sleep,clock,gettickcount,QueryPerformanceCounter
- 时间的函数,sleep,clock,gettickcount,QueryPerformanceCounter
- 时间的函数Sleep,clock,GetTickCount,QueryPerformanceCounter
- 时间的函数,sleep,clock,gettickcount,QueryPerformanceCounter
- 时间的函数,sleep,clock,gettickcount,QueryPerformanceCounter
- (转)windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTime
- QueryPerformanceCounter精确计算执行时间
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTim
- //Windows系统下可以用 time(),clock(),timeGetTime(),GetTickCount(),QueryPerformanceCounter()来对一段程序代码进行计时
- C++利用QueryPerformanceCounter计算代码运行时间
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTim
- windows平台时间函数性能比较QueryPerformanceCounter,GetTickCount,ftime,time,GetLocalTime,GetSystemTimeAsFileTim
- 如何精确计算程序运行时间——精确获取时间(QueryPerformanceCounter)
- C/C++日期时间使用方法,struct tm, time_t, clock_t,计算循环所用时间
- 精度试验结果报告Sleep, GetTickCount, timeGetTime, QueryPerformanceCounter