1<?PHP2 Header("content-type:text/html; Charset=utf-8 ");3 classTimer {4 var $StartTime= 0;5 var $StopTime= 0;6 var $TimeSpent= 0;7 8 functionstart () {9 $this-StartTime =Microtime();Ten } One A functionStop () { - $this-StopTime =Microtime(); - } the - functionspent () { - if($this-timespent) { - return $this-timespent; +}Else { - $StartMicro=substr($thisStartTime, 0, 10); + $StartSecond=substr($thisStartTime, 11, 10); A $StopMicro=substr($thisStopTime, 0, 10); at $StopSecond=substr($thisStopTime, 11, 10); - $start=Floatval($StartMicro) +$StartSecond; - $stop=Floatval($StopMicro) +$StopSecond; - $this-Timespent =$stop-$start; - return round($thisTimespent, 8). Seconds; - } in}//End Function spent (); - to}//End Class timer; + - $timer=Newtimer (); the $timer-start (); * //Start-----Test code block $ $link=Mysqli_connect(' localhost ', ' root ', ' 123456 ', ' SDK ', ' 3306 ') or die(' Connect false! ');Panax Notoginseng $redis=NewRedis (); - $redisConnect (' 127.0.0.1 ', 6379); the $redis-Flushall (); + $query= <<<ETO ASELECT * from ' table ' asT1 the JOIN(SELECTROUND(RAND() * ((SELECTMAX(ID) from ' table ')-(SELECTMIN(ID) from ' table ') + (SELECTMIN(ID) from ' table ') asId asT2 +WHERE t1.id >= t2.id ORDER by t1.id LIMIT 1; - ETO; $ $result=Mysqli_query($link,$query); $ foreach($result as $value) { - foreach($value as $key=$val) { - $res[$key] =$val; the } - }Wuyi $redis-Mset ($res); the $keys=$redisKeys (' * '); - Var_dump($keys); Wu Echo' <br/>--above is redis keys--<br/> '; - Var_dump($redis-Mget ($keys)); About Echo' <br/>--above is redis keys of values--<br/> '; $ //End-----Test code block - Mysqli_close($link); - $timer-stop (); - Echo' </br> run time: '.$timer-spent (); A unset($timer);
Class to test the execution time of a PHP code block