3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements \Iterator { private $items = []; public function __construct(iterable $items){ $this->items = $items; } public function rewind() : void { reset($this->items); } public function key() { return key($this->items); } public function next() { $n = next($this->items); return is_object($n) ? clone($n) : $n; } public function valid() : bool { $key = key($this->items); return $key !== null && $key !== false; } public function current() { $current = current($this->items); return clone($current); } } $items = []; for($i=0; $i<6; $i++){ $items[$i] = new stdClass(); $items[$i]->number = random_int(1,1000); } $test = new Test($items); foreach($test as $t){ echo \spl_object_hash($t)."\n"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.0.80.0140.00616.98
8.0.70.0070.01116.94
8.0.60.0120.00616.85
8.0.50.0060.01216.82
8.0.30.0140.00616.97
8.0.20.0130.00617.00
8.0.10.0120.00617.02
8.0.00.0080.00817.03
7.4.210.0120.00616.52
7.4.200.0160.00316.60
7.4.190.0150.00316.50
7.4.180.0060.01116.70
7.4.160.0040.01516.60
7.4.150.0000.01616.68
7.4.140.0050.01016.57
7.4.130.0130.00416.47
7.4.120.0070.01016.42
7.4.110.0030.01216.37
7.4.100.0060.00916.50
7.4.90.0110.00716.44
7.4.80.0130.00616.41
7.4.70.0000.00016.55
7.4.60.0090.00616.39
7.4.50.0130.00516.52
7.4.40.0070.00816.30
7.4.30.0090.00716.46
7.4.20.0040.01416.41
7.4.10.0060.01116.49
7.4.00.0070.01316.56
7.3.290.0030.01316.31
7.3.280.0040.01416.33
7.3.270.0100.01016.41
7.3.260.0120.00616.30
7.3.250.0120.00616.33
7.3.240.0110.00716.29
7.3.230.0110.00616.32
7.3.220.0100.00716.27
7.3.210.0150.01016.28
7.3.200.0130.00916.26
7.3.190.0060.01016.30
7.3.180.0110.00716.29
7.3.170.0070.01016.18
7.3.160.0090.01216.32
7.3.150.0140.01016.29
7.3.140.0090.00916.30
7.3.130.0110.00816.29
7.3.120.0060.00916.32
7.3.110.0000.01816.20
7.3.100.0130.00316.17
7.3.90.0070.01016.48
7.3.80.0150.00616.27
7.3.70.0060.01516.46
7.3.60.0090.00616.38
7.3.50.0130.00316.45
7.3.40.0060.01016.45
7.3.30.0090.00616.46
7.3.20.0160.01316.46
7.3.10.0100.01016.47
7.3.00.0170.01016.41

preferences:
43.04 ms | 743 KiB | 5 Q