3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Action { /** @var \Iterator */ public $generator; public function __construct(array $data) { $this->generator = new class($this, $data) extends \ArrayIterator { /** @var Action */ public $action; public function __construct(Action $action, array $data) { $this->action = $action; // circular ref (can be any custom iterator) parent::__construct($data); } }; echo '-- c ' . spl_object_id($this) . "\n"; } public function __destruct() { echo '-- d ' . spl_object_id($this) . "\n"; } /** * @return $this */ public function filter() { $filterFx = function ($row) { return $row !== $this; // always true, dummy use $this }; $this->generator = new \CallbackFilterIterator($this->generator, $filterFx); $this->generator->rewind(); return $this; } /** * @return $this */ public function limit(int $limit = null, int $offset = 0) { $this->generator = new \LimitIterator($this->generator, $offset, $limit ?? -1); $this->generator->rewind(); return $this; } } $action = new Action(['a', 'b']); print_r(iterator_to_array($action->generator)); $action = null; gc_collect_cycles(); $action = new Action(['a', 'b']); $action->filter(); print_r(iterator_to_array($action->generator)); $action = null; gc_collect_cycles(); $action = new Action(['a', 'b']); $action->filter()->limit(1); print_r(iterator_to_array($action->generator)); $action = null; gc_collect_cycles(); echo '----------------' . "\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.5.00.0110.01120.30
8.4.150.0010.00014.05
8.4.140.0160.00619.67
8.4.130.0060.00417.73
8.4.120.0080.01222.50
8.4.110.0040.00519.08
8.4.100.0050.00418.05
8.4.90.0120.00920.45
8.4.80.0070.00620.65
8.4.70.0130.00718.76
8.4.60.0100.01020.41
8.4.50.0140.00620.74
8.4.40.0120.00317.77
8.4.30.0100.01020.52
8.4.20.0070.02017.90
8.4.10.0120.00419.67
8.3.280.0110.00918.38
8.3.270.0140.00516.85
8.3.260.0120.00916.71
8.3.250.0110.00718.92
8.3.240.0100.01117.02
8.3.230.0150.00516.95
8.3.220.0100.00919.00
8.3.210.0080.00516.73
8.3.200.0050.00416.55
8.3.190.0150.00517.22
8.3.180.0120.00718.92
8.3.170.0090.00917.16
8.3.160.0060.01216.82
8.3.150.0100.01017.41
8.3.140.0060.00317.04
8.3.130.0050.00318.51
8.3.120.0000.00819.15
8.3.110.0060.00320.94
8.3.100.0140.00316.66
8.3.90.0060.00326.77
8.3.80.0030.00616.88
8.3.70.0070.01016.58
8.3.60.0120.00918.30
8.3.50.0060.01220.03
8.3.40.0120.00618.69
8.3.30.0100.00518.48
8.3.20.0040.00424.18
8.3.10.0080.00024.66
8.3.00.0000.00926.16
8.2.290.0100.00917.20
8.2.280.0130.00419.95
8.2.270.0070.00316.74
8.2.260.0060.00317.54
8.2.250.0030.00618.23
8.2.240.0090.00017.37
8.2.230.0060.00322.58
8.2.220.0000.00924.06
8.2.210.0060.00926.77
8.2.200.0050.00516.75
8.2.190.0210.00018.29
8.2.180.0160.00625.92
8.2.170.0060.00918.95
8.2.160.0100.00322.96
8.2.150.0050.00225.66
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0040.00419.77
8.2.110.0060.00320.32
8.2.100.0040.00420.47
8.1.330.0130.00622.05
8.1.320.0050.00416.48
8.1.310.0100.00716.99
8.1.300.0060.00617.77
8.1.290.0060.00330.84
8.1.280.0090.00625.92
8.1.270.0040.00423.99
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0030.00618.86
8.1.230.0030.00720.36
8.1.40.0060.00517.43
8.0.170.0020.01016.89
7.4.280.0020.00616.49

preferences:
89.62 ms | 403 KiB | 5 Q