CopyCode The Code is as follows: <? PHP
Class Timer
{
VaR $ time_start;
VaR $ time_end;
Function _ construct ()
{
$ This-> time_start = 0;
$ This-> time_end = 0;
}
Function timer ()
{
$ This->__ construct ();
}
Function start ()
{
List ($ USEC, $ Sec) = explode ("", microtime ());
$ This-> time_start = (float) $ USEC + (float) $ sec;
}
Function stop ()
{
List ($ USEC, $ Sec) = explode ("", microtime ());
$ This-> time_end = (float) $ USEC + (float) $ sec;
}
Function show ($ output = false)
{
$ Total = $ this-> time_end-$ this-> time_start;
If ($ output ){
Echo $ total, "Sec ";
Return true;
}
Return $ total. "Sec ";
}
}
?>
<? PHP
Echo 'check prime <br/> ';
Function isprime ($ I)
{
If ($ I <2)
{
Return false;
}
// Var $ iterator;
For ($ iterator = 2; $ iterator <= SQRT ($ I); $ iterator ++)
{
If ($ I % $ iterator = 0)
{
Return false;
}
}
Return true;
}
$ Sw = new timer ();
$ Sw-> Start ();
For ($ j = 1; $ j <100; $ J ++)
{
If (isprime ($ J ))
{
Echo 'true <br/> ';
}
Else
{
Echo 'false <br/> ';
}
}
$ Sw-> stop ();
$ Sw-> show (true );
?>