timer_stop( int|bool $display, int $precision = 3 ): string

Retrieves or displays the time from the page start to when function is called.


Parameters

$display int|bool Required
Whether to echo or return the results. Accepts 0|false for return, 1|true for echo. Default 0|false.
$precision int Optional
The number of digits from the right of the decimal to display.

Default: 3


Top ↑

Return

string The "second.microsecond" finished time calculation. The number is formatted for human consumption, both localized and rounded.


Top ↑

Source

File: wp-includes/load.php. View all references

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;
}


Top ↑

Changelog

Changelog
Version Description
0.71 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Determine length of time to render page with a precision of 3, 5 and 10 digits.

    echo( 'Seconds: ' . timer_stop( 0 ) . '<br />' );
    echo( 'Seconds: ' . timer_stop( 0, 5 ) . '<br />' );
    echo( 'Seconds: ' . timer_stop( 0, 10 ) . '<br />' );

    Output:

    Seconds: 0.815
    Seconds: 0.81551
    Seconds: 0.8155429363

You must log in before being able to contribute a note or feedback.