1 //algorithm Time Test Datum method (quantitative analysis) Large O method (qualitative analyses)2 //The following is the benchmark method3#include"iostream"4#include"Cstdio"5#include"CTime"6#include"windows.h"7 using namespacestd;8 intMain ()9 {Ten //fa Yi Oneclock_t Start1,end1;//clock_t Required header file # include "CTime" A DoubleDuration1; - -Start1=clock ();//returns the number of milliseconds that the program is running to this location the:: Sleep ( the);//Delay function parameter is milliseconds header file # include "windows.h" note two colons and uppercase S -end1=clock (); -Duration1= (Double) (End1-start1)/clocks_per_sec;//for output seconds, millisecond seconds -cout<<"The clock_t time is"<<duration1<<"S"<<Endl; + - + A //Method Two at time_t Start2,end2; - -Start2=time (0);//gets the number of seconds from 1970 1 1 0:0:0 to the present (note Unit is seconds) -:: Sleep ( the); -End2=time (0); - Doubleduration2=end2-Start2; incout<<"The time_t time is"<<duration2<<"S"<<Endl; -}View Code
Algorithm Time Test