1. 程式人生 > >【C語言】程式執行時間測量

【C語言】程式執行時間測量

今天在做一個大資料檔案建立的時候,為了測量建立所用的時間,特意研究了下,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;