PHP Log program Execution time Microtime

Source: Internet
Author: User
/** * 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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.