VS測試程式執行時間
阿新 • • 發佈:2019-01-26
Method1
使用GetTickCount()函式
#include <windows.h>
void main()
{
long start = GetTickCount(); //開始時間
{
//測試程式段
}
long finish = GetTickCount(); //結束時間
long t = finish-start;
printf("The run time is:%9.3lf\n", t, "ms!\n"); //輸出時間
}
Method2
使用clock()函式
#include "time.h"
void main()
{
long start = clock(); //開始時間
{
//測試程式段
}
long finish = clock(); //結束時間
long t = finish-start;
printf("The run time is:%9.3lf\n", t, "ms!\n"); //輸出時間
}