3v4l.org

run code in 300+ PHP versions simultaneously
<?php class inConstruct { function __construct($array) { foreach ($array as $key => $value) { if ($key == 100) { echo "Done"; } } } } class inMethod { function __construct($array) { $this->doThat($array); } function doThat($array){ foreach ($array as $key => $value) { if ($key == 100) { echo "Done"; } } } } $questions = range("a", "z", 1); for($i=0;$i<10;$i++) {} $start = microtime(); ## For inMethod for ($i=0; $i < 1000; $i++) { $m = new inConstruct($questions); unset($m); } echo (microtime() - $start); echo "\n"; $start = microtime(); ## For inConstruct for ($i=0; $i < 1000; $i++) { $m = new inMethod($questions); unset($m); } echo (microtime() - $start);

preferences:
23.77 ms | 402 KiB | 5 Q