3v4l.org

run code in 300+ PHP versions simultaneously
<?php class WrappingIterator implements \Iterator { private $index; private $iterator; public function __construct(int $index, Traversable $traversable) { printf('Creating %s %d' . PHP_EOL, static::class, $index); $this->index = $index; $this->iterator = $this->wrapTraversable($traversable); } public function __destruct() { printf('Destroying %s %d' . PHP_EOL, static::class, $this->index); } protected function destroyWrappedIterator() { $this->iterator = null; } public function current() { return $this->iterator->current(); } public function next() { $this->iterator->next(); } public function key() { return $this->iterator->key(); } public function valid() { return $this->iterator->valid(); } public function rewind() { $this->iterator->rewind(); } private function wrapTraversable(Traversable $traversable) { foreach ($traversable as $key => $value) { yield $key => $value; } } } class DestroyingIterator extends WrappingIterator { public function __destruct() { parent::__destruct(); $this->destroyWrappedIterator(); } } class WrappedIterator extends ArrayIterator { public function __construct(int $index) { parent::__construct([1, 2, 3, 4]); $this->index = $index; } public function __destruct() { printf('Destroying WrappedIterator %d' . PHP_EOL, $this->index); } } function testIterator(string $class, int $limit = 20) { printf('Starting run with class "%s" and limit "%d"' . PHP_EOL, $class, $limit); gc_enable(); gc_collect_cycles(); for ($i = 1; $i <= $limit; $i++) { $iterator = new $class($i, new WrappedIterator($i)); $iterator->current(); if ($i % 5 === 0) { gc_collect_cycles(); } } gc_collect_cycles(); echo 'Done', PHP_EOL; } testIterator(WrappingIterator::class); testIterator(DestroyingIterator::class);

Abusive script

This script was stopped while abusing our resources

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.3.110.0090.00020.94
8.3.100.0070.00324.06
8.3.90.0090.00026.77
8.3.80.0030.00718.43
8.3.70.0100.01016.75
8.3.60.0150.00416.62
8.3.50.0070.00718.28
8.3.40.0160.00018.79
8.3.30.0130.00319.02
8.3.20.0090.00021.82
8.3.10.0040.00421.90
8.3.00.0000.00822.38
8.2.230.0060.00322.58
8.2.220.0050.00537.54
8.2.210.0110.00726.77
8.2.200.0070.00316.88
8.2.190.0150.00416.58
8.2.180.0150.00318.14
8.2.170.0060.00922.96
8.2.160.0090.00620.53
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0040.00426.16
8.2.110.0070.00321.12
8.2.100.0140.00017.90
8.2.90.0080.00017.61
8.2.80.0090.00018.04
8.2.70.0050.00317.91
8.2.60.0040.00418.03
8.2.50.0090.00018.10
8.2.40.0050.00321.19
8.2.30.0000.00819.38
8.2.20.0040.00418.32
8.2.10.0030.00518.96
8.2.00.0080.00019.38
8.1.290.0070.00318.88
8.1.280.0090.00925.92
8.1.270.0060.00920.39
8.1.260.0080.00026.35
8.1.250.0030.00528.09
8.1.240.0090.00023.92
8.1.230.0120.00022.68
8.1.220.0080.00017.79
8.1.210.0030.00618.77
8.1.200.0090.00317.35
8.1.190.0030.00617.23
8.1.180.0030.00618.10
8.1.170.0080.00020.78
8.1.160.0060.00319.06
8.1.150.0000.00718.90
8.1.140.0070.00018.95
8.1.130.0040.00419.24
8.1.120.0070.00417.37
8.1.110.0040.00417.47
8.1.100.0020.00517.46
8.1.90.0030.00517.30
8.1.80.0030.00617.48
8.1.70.0030.00317.44
8.1.60.0050.00317.46
8.1.50.0040.00417.55
8.1.40.0060.00317.50
8.1.30.0040.00417.57
8.1.20.0060.00317.68
8.1.10.0050.00317.53
8.1.00.0030.00617.60
8.0.300.0030.00519.60
8.0.290.0040.00416.88
8.0.280.0000.00818.53
8.0.270.0040.00417.32
8.0.260.0000.00716.77
8.0.250.0000.00816.93
8.0.240.0000.00716.95
8.0.230.0040.00417.06
8.0.220.0040.00416.89
8.0.210.0040.00417.01
8.0.200.0000.00717.09
8.0.190.0000.00916.97
8.0.180.0000.00816.97
8.0.170.0030.00617.05
8.0.160.0050.00317.03
8.0.150.0000.00816.88
8.0.140.0000.00716.85
8.0.130.0030.00313.38
8.0.120.0000.00916.84
8.0.110.0000.00716.99
8.0.100.0060.00316.84
8.0.90.0000.00917.00
8.0.80.0130.00316.93
8.0.70.0000.00816.86
8.0.60.0000.00716.98
8.0.50.0040.00416.87
8.0.30.0100.00716.99
8.0.20.0170.00316.86
8.0.10.0030.00517.05
8.0.00.0200.00016.64
7.4.330.0000.00615.55
7.4.320.0030.00316.52
7.4.300.0000.00716.61
7.4.290.0030.00316.60
7.4.280.0030.00616.46
7.4.270.0040.00416.45
7.4.260.0030.00313.32
7.4.250.0030.00316.61
7.4.240.0040.00516.51
7.4.230.0000.00716.67
7.4.220.0050.00216.65
7.4.210.0090.00816.58
7.4.200.0030.00416.63
7.4.130.0040.01616.43
7.4.120.0160.00316.47
7.4.110.0040.01316.51
7.4.100.0060.01216.60
7.4.90.0070.01116.55
7.4.80.0060.01219.39
7.4.70.0080.00916.56
7.4.60.0090.00916.64
7.4.50.0030.01416.34
7.4.40.0110.01116.64
7.4.00.0030.01015.16
7.3.330.0030.00516.39
7.3.320.0000.00513.26
7.3.310.0030.00516.39
7.3.300.0040.00416.32
7.3.290.0050.00316.27
7.3.280.0040.01216.35
7.3.260.0090.01116.54
7.3.240.0090.01116.48
7.3.230.0090.00916.63
7.3.210.0050.01416.67
7.3.200.0120.00616.71
7.3.190.0100.01016.43
7.3.180.0100.00716.57
7.3.170.0030.01416.37
7.3.160.0080.00816.60
7.3.110.0100.00714.85
7.3.100.0130.00514.90
7.3.90.0100.00614.81
7.3.80.0090.00914.98
7.3.70.0070.00914.81
7.3.60.0070.00814.84
7.3.50.0070.00814.75
7.3.40.0080.00714.79
7.3.30.0060.00914.79
7.3.20.0070.00814.84
7.3.10.0070.00914.85
7.3.00.0070.00914.82
7.2.330.0060.01316.52
7.2.320.0040.01616.57
7.2.310.0060.01216.82
7.2.300.0070.01716.45
7.2.290.0050.01316.80
7.2.240.0090.01115.01
7.2.230.0070.01015.09
7.2.220.0030.01314.93
7.2.210.0110.00715.06
7.2.200.0090.00914.93
7.2.190.0090.00814.98
7.2.180.0090.00614.96
7.2.170.0080.00714.97
7.2.160.0050.01115.13
7.2.150.0100.00515.10
7.2.140.0070.00915.18
7.2.130.0090.00714.99
7.2.120.0080.00815.14
7.2.110.0050.01115.17
7.2.100.0100.00715.14
7.2.90.0140.00715.02
7.2.80.0060.01015.06
7.2.70.0110.00715.20
7.2.60.0070.01015.08
7.2.50.0070.01115.12
7.2.40.0150.00815.11
7.2.30.0140.00615.01
7.2.20.0110.00915.11
7.2.10.0110.01014.95
7.2.00.0090.01015.17
7.1.330.0120.00713.90
7.1.320.0050.01313.93
7.1.310.0080.00713.97
7.1.300.0060.00813.72
7.1.290.0100.00413.91
7.1.280.0070.00713.79
7.1.270.0090.00513.90
7.1.260.0080.00714.06
7.1.250.0080.00613.90

preferences:
152.77 ms | 403 KiB | 5 Q