/** * Logger Program time---can only record continuous call modifier * @param $time _key record key, multiple executions can specify the same key * @returnnone no return value, directly get the global variable $time_arr, If the call in the method needs to be first global once **/function showexecutime ($time _key = ") {global $time _arr, $time _start, $time _end, $time _num;$ Time_now = Microtime (True); if (! $time _num) {$time _num = 0;} $time _num++;if ($time _num%2 = = 1) {$time _start = $time _now;} else {$time _end = $time _now;} if ($time _num%2 = = 0 && $time _start && $time _end) {$time = $time _end-$time _start;if ($time _key) {$t ime_arr[$time _key] + = $time;} else {$time _arr[] = $time;} $time _arr[' total ' + = $time;}} /** * Logger Program Time---can be called multiple times * @param $time _key record key, multiple executions can specify the same key * @returnnone no return value, directly get the global variable $time_arr, If the call in the method requires a global first time **/function showexecutime ($time _key = ") {global $time _arr, $time _key_arr, $time _num; $time _now = Microtime (True); if (! $time _key) {if (! $time _num) {$time _num = 0;} $time _num++; $time _key = Floor (($time _num+1)/2)-1;} Record whether this is the start or end time if (!isset ($time _key_arr[$time _key)) {$time _key_arr[$time_key][' num '] = 0;} $time _key_arr[$time _key][' num ']++;if ($time _key_arr[$time _key][' num ']%2 = = 1) {$time _key_arr[$time _key][' time_ Start '] = $time _now;} else {$time _key_arr[$time _key][' time_end ') = $time _now;} If 2 consecutive records, calculate if ($time _key_arr[$time _key][' num ']%2 = = 0 && $time _key_arr[$time _key][' Time_start '] & & $time _key_arr[$time _key][' time_end ') {$time = $time _key_arr[$time _key][' time_end ')-$time _key_arr[$time _key] [' Time_start ']; $time _arr[$time _key] + = $time; $time _arr[' total ' + = $time;}} Showexecutime (' all '); Showexecutime (); Sleep (1), Showexecutime (' all ');//////sleep (1); Showexecutime (); sleep (1); Showexecutime (); sleep (1); Showexecutime (); Showexecutime (' a '); sleep (1); Showexecutime (' a ');//Showexecutime (' all ') ;//////print_r ($time _arr);p rint_r ($time _key_arr);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP recording program execution time Microtime, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.