Are there any best practices for accurately calculating and displaying the page generation time in PHP?

Calculating and displaying the page generation time in PHP can help in monitoring and optimizing the performance of your website. One way to accurately calculate the page generation time is by capturing the start and end timestamps, and then calculating the difference between them. This can be achieved by using the microtime() function before and after the main content of the page.

<?php
// Start timestamp
$start = microtime(true);

// Main content of the page
// ...

// End timestamp
$end = microtime(true);

// Calculate page generation time
$generation_time = $end - $start;

// Display the page generation time
echo "Page generated in " . round($generation_time, 4) . " seconds";
?>