使用GetTickCount()函數(shù)
- 功能:返回從操作系統(tǒng)啟動所經(jīng)過(elapsed)的毫秒數(shù)
- 返回值:DWORD
#include <stdio.h>
#include <iostream>
#include <windows.h>
int main(){
DWORD start_time = GetTickCount(); //開始時間
for (int i = 0; i < 100000000; i++) //計算for循環(huán)的時間
i++;
DWORD end_time = GetTickCount(); //結(jié)束時間
std::cout << "The run time is " << (end_time - start_time) << " ms" << std::endl;
system("pause");
return 0;
}