When the first generation is generated, it is initialized. After you want to test the CODE, you call countTime () directly, then call Result (); convenient .. You can also test the total time, Refreshing the statement comment out, just ... huh
PHP code:
PHP
Class timecount {
Var $ baseime;
Var $ printmsg;
Var $ PATTERN;
Var $ PrintName;
Function Timecount ($ name) {
$ this-> Basetime = microtime ();
$ this-> printmsg = array ();
$ this-> TotalTime = 0;
$ this-> pattern = '^ ([^] ) (. )';
$ this-> printname = $ name;
}
Function Countime ($ label) {
$ currenttime = microtime ();
EREG ($ THIS-> Pattern, $ CURRENTTIME, $ C);
$ CU = DoubleVal ($ C [2]) DoubleVal ($ C [1]);
EREG ($ this-> Pattern, $ this-> Basetime, $ b);
$ ba = doublevalval ($ b [2]) DoubleVal ($ b [1]);
$ DIFF = ABS ($ CU- $ BA);
$ this-> printmsg [] = Sprintf ("
%-20S% S S", $ Label, $ DIFF);
/ **
* This assignment use to refresh the basetime;
* When You needed to add the totaltime, please remove the comments.
* @ Default Remive Comments;
* /
$ this-> Basetime = $ CURRENTTIME;
}
Function result () {
Echo $ this-> PrintName;
Foreach ($ this-> printmsg as $ v) {
ECHO $ V;
}
}
}
$ TIMETEST = New Timecount ('TIMING:');
For ($ I = 0; $ i <99999; $ i ) {}
$ TIMETEST-> COUNTTIME ("THE FIRST CIRCLE:");
For ($ I = 0; $ i <99999; $ i ) {}
$ TIMETEST-> COUNTTIME ("The Second Circle:");
$ TIMETEST-> Result ();
?>
Second Function Getmicrotime () {list ($ USEC, $ Sec) = Explode ("", microtime ()); Return ((Double) $ sec (Double) $ sec);} $ start = getMicrotime (); // Other programs / / -> $ end = getMicRotime (); $ d = $ END- $ start; echo "program execution". $ D;