The following code displays in the footer the number of database queries the page executed, the time it took to run those queries, and the memory usage of the page.
function sv_performance( $visible = false ) {
$stat = sprintf( '%d queries in %.3f seconds, using %.2fMB memory',
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
echo $visible ? $stat : "<!-- {$stat} -->" ;
}
add_action( 'wp_footer', 'sv_performance', 20 );The result appears as a comment in the footer. Check the page source to see it:
<!-- 33 queries in 1.532 seconds, using 48.75MB memory -->For more performance optimization, see Improve WordPress Loading Time.