close

第一種方式:

#include<ctime>

 

srand(time(0))

int time1,time2;

time1 = time(0);   //start program time

//execute the program

Time2 = time(0);  //finish program time

 

Cout<<time2-time1<<” seconds ”<<endl;

 

第二種方式:

clock_t start, end, diff_time;

start = clock();//開始時間

//execute the program

end = clock();//結束時間

diff_time =(double) (end-start)/(double)CLOCKS_PER_SEC;//秒數

cout<<endl<<"Time: "<<diff_time<<" seconds "<<endl;

 

在多工系統下測試不準,因為同時間OS會處理其他process

用來比較2programs的效能

arrow
arrow
    全站熱搜

    flyinsky76 發表在 痞客邦 留言(0) 人氣()