timer_stop

The timeline below displays how wordpress function timer_stop has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Retrieves or displays the time from the page start to when function is called.
 *
 * @since 0.71
 *
 * @global float   $timestart Seconds from when timer_start() is called.
 * @global float   $timeend   Seconds from when function is called.
 *
 * @param int|bool $display   Whether to echo or return the results. Accepts 0|false for return,
 *                            1|true for echo. Default 0|false.
 * @param int      $precision The number of digits from the right of the decimal to display.
 *                            Default 3.
 * @return string The "second.microsecond" finished time calculation. The number is formatted
 *                for human consumption, both localized and rounded.
 */
function timer_stop($display = 0, $precision = 3)
{
    global $timestart, $timeend;
    $timeend = microtime(true);
    $timetotal = $timeend - $timestart;
    if (function_exists('number_format_i18n')) {
        $r = number_format_i18n($timetotal, $precision);
    } else {
        $r = number_format($timetotal, $precision);
    }
    if ($display) {
        echo $r;
    }
    return $r;
}

WordPress Version: 4.2

/**
 * Retrieve or display the time from the page start to when function is called.
 *
 * @since 0.71
 *
 * @global float   $timestart Seconds from when timer_start() is called.
 * @global float   $timeend   Seconds from when function is called.
 *
 * @param int|bool $display   Whether to echo or return the results. Accepts 0|false for return,
 *                            1|true for echo. Default 0|false.
 * @param int      $precision The number of digits from the right of the decimal to display.
 *                            Default 3.
 * @return string The "second.microsecond" finished time calculation. The number is formatted
 *                for human consumption, both localized and rounded.
 */
function timer_stop($display = 0, $precision = 3)
{
    global $timestart, $timeend;
    $timeend = microtime(true);
    $timetotal = $timeend - $timestart;
    $r = function_exists('number_format_i18n') ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
    if ($display) {
        echo $r;
    }
    return $r;
}

WordPress Version: 3.9

/**
 * Retrieve or display the time from the page start to when function is called.
 *
 * @since 0.71
 *
 * @global float $timestart Seconds from when timer_start() is called.
 * @global float $timeend   Seconds from when function is called.
 *
 * @param int $display   Whether to echo or return the results. Accepts 0|false for return,
 *                       1|true for echo. Default 0|false.
 * @param int $precision The number of digits from the right of the decimal to display.
 *                       Default 3.
 * @return string The "second.microsecond" finished time calculation. The number is formatted
 *                for human consumption, both localized and rounded.
 */
function timer_stop($display = 0, $precision = 3)
{
    global $timestart, $timeend;
    $timeend = microtime(true);
    $timetotal = $timeend - $timestart;
    $r = function_exists('number_format_i18n') ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
    if ($display) {
        echo $r;
    }
    return $r;
}

WordPress Version: 3.7

/**
 * Return and/or display the time from the page start to when function is called.
 *
 * You can get the results and print them by doing:
 * <code>
 * $nTimePageTookToExecute = timer_stop();
 * echo $nTimePageTookToExecute;
 * </code>
 *
 * Or instead, you can do:
 * <code>
 * timer_stop(1);
 * </code>
 * which will do what the above does. If you need the result, you can assign it to a variable, but
 * in most cases, you only need to echo it.
 *
 * @since 0.71
 * @global float $timestart Seconds from when timer_start() 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 $precision The amount of digits from the right of the decimal to display. Default is 3.
 * @return float The "second.microsecond" finished time calculation
 */
function timer_stop($display = 0, $precision = 3)
{
    // if called like timer_stop(1), will echo $timetotal
    global $timestart, $timeend;
    $timeend = microtime(true);
    $timetotal = $timeend - $timestart;
    $r = function_exists('number_format_i18n') ? number_format_i18n($timetotal, $precision) : number_format($timetotal, $precision);
    if ($display) {
        echo $r;
    }
    return $r;
}