WordPress.org

Make WordPress Core

Ticket #19157: 19157.diff

File 19157.diff, 2.6 KB (added by solarissmoke, 7 years ago)

Use microtime() with get_as_float

  • wp-includes/load.php

     
    182182}
    183183
    184184/**
    185  * PHP 4 standard microtime start capture.
     185 * PHP 5 standard microtime start capture.
    186186 *
    187187 * @access private
    188188 * @since 0.71
    189  * @global int $timestart Seconds and microseconds added together from when function is called.
     189 * @global float $timestart Seconds from when function is called.
    190190 * @return bool Always returns true.
    191191 */
    192192function timer_start() {
    193193        global $timestart;
    194         $mtime = explode( ' ', microtime() );
    195         $timestart = $mtime[1] + $mtime[0];
     194        $timestart = microtime( true );
    196195        return true;
    197196}
    198197
     
    213212 * in most cases, you only need to echo it.
    214213 *
    215214 * @since 0.71
    216  * @global int $timestart Seconds and microseconds added together from when timer_start() is called
    217  * @global int $timeend Seconds and microseconds added together from when function is called
     215 * @global float $timestart Seconds from when timer_start() is called
     216 * @global float $timeend Seconds from when function is called
    218217 *
    219218 * @param int $display Use '0' or null to not echo anything and 1 to echo the total time
    220219 * @param int $precision The amount of digits from the right of the decimal to display. Default is 3.
     
    222221 */
    223222function timer_stop( $display = 0, $precision = 3 ) { // if called like timer_stop(1), will echo $timetotal
    224223        global $timestart, $timeend;
    225         $mtime = microtime();
    226         $mtime = explode( ' ', $mtime );
    227         $timeend = $mtime[1] + $mtime[0];
     224        $timeend = microtime( true );
    228225        $timetotal = $timeend - $timestart;
    229226        $r = ( function_exists( 'number_format_i18n' ) ) ? number_format_i18n( $timetotal, $precision ) : number_format( $timetotal, $precision );
    230227        if ( $display )
  • wp-includes/wp-db.php

     
    14431443         * @return true
    14441444         */
    14451445        function timer_start() {
    1446                 $mtime            = explode( ' ', microtime() );
    1447                 $this->time_start = $mtime[1] + $mtime[0];
     1446                $this->time_start = microtime( true );
    14481447                return true;
    14491448        }
    14501449
     
    14531452         *
    14541453         * @since 1.5.0
    14551454         *
    1456          * @return int Total time spent on the query, in milliseconds
     1455         * @return float Total time spent on the query, in seconds
    14571456         */
    14581457        function timer_stop() {
    1459                 $mtime      = explode( ' ', microtime() );
    1460                 $time_end   = $mtime[1] + $mtime[0];
    1461                 $time_total = $time_end - $this->time_start;
    1462                 return $time_total;
     1458                return ( microtime( true ) - $this->time_start );
    14631459        }
    14641460
    14651461        /**