Is it recommended to use manual start and stop functions in a benchmarking class rather than overloading the destructor in PHP?

It is recommended to use manual start and stop functions in a benchmarking class rather than overloading the destructor in PHP. This ensures better control over when the benchmarking starts and stops, avoiding any unexpected behavior that may occur with destructor overloading.

class Benchmark {
    private $startTime;

    public function start() {
        $this->startTime = microtime(true);
    }

    public function stop() {
        $endTime = microtime(true);
        $executionTime = $endTime - $this->startTime;
        echo "Execution time: " . $executionTime . " seconds";
    }
}

$benchmark = new Benchmark();
$benchmark->start();

// Code to benchmark

$benchmark->stop();