有许多专门的测试工具,测试的准确性很高,本文说的是一些简单的测试方法,这些方法多数是记录CPU的运行时间,没有考虑操作系统的分时复用,不过不太严格的情况都可一用。
1. #include <time.h>
long start=clock(),end(0);
//ToDo:process code
end=clock();
long result=(end-start)/1000
2. windows 平台
#include <windows.h>
double start=getticktime(),end(0);
//ToDo:process code
end=getticktime();
double result=end-start;
3.windows 平台
#include <windows.h>
LARGE_INTEGER frequency,start,end;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
//ToDO:process code
QueryPerformanceCounter(&end);
double d = (double)(end.QuadPart - start.QuadPart) / (double)frequency.QuadPart * 1000.0;
4.根据线程而来的
CThreadTime ElapsedTime;
ElapsedTime.BeginGetE
1. #include <time.h>
long start=clock(),end(0);
//ToDo:process code
end=clock();
long result=(end-start)/1000
2. windows 平台
#include <windows.h>
double start=getticktime(),end(0);
//ToDo:process code
end=getticktime();
double result=end-start;
3.windows 平台
#include <windows.h>
LARGE_INTEGER frequency,start,end;
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
//ToDO:process code
QueryPerformanceCounter(&end);
double d = (double)(end.QuadPart - start.QuadPart) / (double)frequency.QuadPart * 1000.0;
4.根据线程而来的
CThreadTime ElapsedTime;
ElapsedTime.BeginGetE