Ask for a float from microtime() for timer_start(), timer_stop(). Clarify docs. props solarissmoke, fixes #19157.

git-svn-id: http://svn.automattic.com/wordpress/trunk@19611 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2011-12-20 21:36:53 +00:00
parent 827f57ce22
commit 6424c5b733
2 changed files with 9 additions and 16 deletions

View File

@ -182,17 +182,16 @@ function wp_maintenance() {
} }
/** /**
* PHP 4 standard microtime start capture. * PHP 5 standard microtime start capture.
* *
* @access private * @access private
* @since 0.71 * @since 0.71
* @global int $timestart Seconds and microseconds added together from when function is called. * @global float $timestart Seconds from when function is called.
* @return bool Always returns true. * @return bool Always returns true.
*/ */
function timer_start() { function timer_start() {
global $timestart; global $timestart;
$mtime = explode( ' ', microtime() ); $timestart = microtime( true );
$timestart = $mtime[1] + $mtime[0];
return true; return true;
} }
@ -213,8 +212,8 @@ function timer_start() {
* in most cases, you only need to echo it. * in most cases, you only need to echo it.
* *
* @since 0.71 * @since 0.71
* @global int $timestart Seconds and microseconds added together from when timer_start() is called * @global float $timestart Seconds from when timer_start() is called
* @global int $timeend Seconds and microseconds added together from when function is called * @global float $timeend Seconds from when function is called
* *
* @param int $display Use '0' or null to not echo anything and 1 to echo the total time * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
* @param int $precision The amount of digits from the right of the decimal to display. Default is 3. * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
@ -222,9 +221,7 @@ function timer_start() {
*/ */
function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_stop(1), will echo $timetotal function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_stop(1), will echo $timetotal
global $timestart, $timeend; global $timestart, $timeend;
$mtime = microtime(); $timeend = microtime( true );
$mtime = explode( ' ', $mtime );
$timeend = $mtime[1] + $mtime[0];
$timetotal = $timeend - $timestart; $timetotal = $timeend - $timestart;
$r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision ); $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
if ( $display ) if ( $display )

View File

@ -1441,8 +1441,7 @@ class wpdb {
* @return true * @return true
*/ */
function timer_start() { function timer_start() {
$mtime = explode( ' ', microtime() ); $this->time_start = microtime( true );
$this->time_start = $mtime[1] + $mtime[0];
return true; return true;
} }
@ -1451,13 +1450,10 @@ class wpdb {
* *
* @since 1.5.0 * @since 1.5.0
* *
* @return int Total time spent on the query, in milliseconds * @return float Total time spent on the query, in seconds
*/ */
function timer_stop() { function timer_stop() {
$mtime = explode( ' ', microtime() ); return ( microtime( true ) - $this->time_start );
$time_end = $mtime[1] + $mtime[0];
$time_total = $time_end - $this->time_start;
return $time_total;
} }
/** /**