Case 1:
Code: Select all
private function abcdefg(){
return 1;
}
public function testfunction()
{
$startTime = microtime(true);
$data = $this->abcdefg();
return "Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n";
}
Time: 0.2101 Seconds
Time: 0.2071 Seconds
Time: 0.1918 Seconds
Time: 0.2040 Seconds
Time: 0.1918 Seconds
Case 2:
However
Code: Select all
private function abcdefg(){
return 1;
}
public function testfunction()
{
$startTime = microtime(true);
$abc = $this->abcdefg();
$data = $abc;
return response()->json("Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n");
}
Time: 0.1757 Seconds
Time: 0.1846 Seconds
Time: 0.1703 Seconds
Time: 0.1877 Seconds
Time: 0.1897 Seconds
I don't understand why the 2 one is faster than the 1 one, can someone explain to me thanks.