In what scenarios would it be more beneficial to use a simple custom function for performance monitoring in PHP scripts instead of a complex class or extension?

When performance monitoring in PHP scripts, it may be more beneficial to use a simple custom function instead of a complex class or extension when the monitoring requirements are straightforward and do not require the complexity and overhead of a class or extension. A custom function can be lightweight, easy to implement, and efficient for basic performance monitoring tasks.

function monitor_performance($start_time) {
    $end_time = microtime(true);
    $execution_time = $end_time - $start_time;
    echo "Script execution time: $execution_time seconds";
}

// Usage example
$start_time = microtime(true);
// Code to monitor performance
monitor_performance($start_time);