【C语言】程序执行时间测量

来源:互联网 发布:js中的短路表达式 编辑:程序博客网 时间:2024/06/07 18:50

今天在做一个大数据文件创建的时候,为了测量创建所用的时间,特意研究了下,windows下时间的获取

1、55ms分辨率的计时:

头文件:#include <windows.h>

GetTickCount() 用法:

DWORD dwStart = GetTickCount();
functon(); // Your program.
DWORD dwEnd = GetTickCount();
DWORD dwTimes = dwEnd - dwStart;

2、10ms分辨率的计时:

头文件:

#include <windows.h>
#include <Mmsystem.h>
#pragma comment( lib,"winmm.lib" )

 timeGetTime()用法:

DWORD dwStart = timeGetTime();
function; // Your program
DWORD dwEnd = timeGetTime();
DWORD dwTimes = dwEnd - dwStart;

3、1ms分辨率的计时:

头文件:

#include <time.h>

clock()用法:

clock_t s_time= clock();

function();

clock_t e_time= clock();

clock_t time = e_time - s_time;



这里有跟全的资料:http://blog.csdn.net/cometdlut/article/details/5839348

0 0
原创粉丝点击