3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TransformingIterator implements \Iterator { /** * @var Iterator */ private $inner; /** * @var callable */ private $valTransformCallback; /** * @var callable */ private $keyTransformCallback; /** * Constructor * * @param Iterator|array $inner * @param callable $valTransformCallback * @param callable $keyTransformCallback * @throws \InvalidArgumentException */ public function __construct($inner, callable $valTransformCallback = null, callable $keyTransformCallback = null) { if ($inner instanceof \Iterator) { $this->inner = $inner; } else if (is_array($inner)) { $this->inner = new \ArrayIterator($inner); } else { throw new \InvalidArgumentException('$inner must be an Iterator or an array'); } $this->valTransformCallback = $valTransformCallback; $this->keyTransformCallback = $keyTransformCallback; } public function current() { return $this->valTransformCallback ? call_user_func($this->valTransformCallback, $this->inner->current()) : $this->inner->current(); } public function next() { $this->inner->next(); } public function key() { return $this->keyTransformCallback ? call_user_func($this->keyTransformCallback, $this->inner->key()) : $this->inner->key(); } public function valid() { return $this->inner->valid(); } public function rewind() { $this->inner->rewind(); } } $it = new TransformingIterator([1,2,3], function ($value) { return $value + 1; }, function ($value) { return $value - 1; }); foreach ($it as $key => $val) { echo $key . '=>' . $val . "\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.3.60.0120.00316.88
8.3.50.0120.00722.00
8.3.40.0040.01118.71
8.3.30.0080.00618.87
8.3.20.0000.00720.21
8.3.10.0040.00423.67
8.3.00.0060.00319.25
8.2.180.0070.01116.75
8.2.170.0070.00722.96
8.2.160.0070.01020.35
8.2.150.0040.00424.18
8.2.140.0100.00324.66
8.2.130.0110.00426.16
8.2.120.0040.01422.20
8.2.110.0030.00622.25
8.2.100.0030.00919.57
8.2.90.0000.00819.27
8.2.80.0000.00817.97
8.2.70.0030.00617.62
8.2.60.0050.00517.93
8.2.50.0070.00318.07
8.2.40.0030.00519.78
8.2.30.0070.00018.33
8.2.20.0000.00817.77
8.2.10.0000.00718.04
8.2.00.0070.00017.64
8.1.280.0100.00725.92
8.1.270.0060.00623.83
8.1.260.0170.00326.35
8.1.250.0060.00328.09
8.1.240.0060.00322.14
8.1.230.0030.00719.04
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0000.00917.24
8.1.190.0110.00017.35
8.1.180.0030.00618.10
8.1.170.0030.00618.56
8.1.160.0030.00522.04
8.1.150.0040.00418.71
8.1.140.0070.00317.43
8.1.130.0070.00017.77
8.1.120.0030.00417.47
8.1.110.0000.00817.48
8.1.100.0000.00717.50
8.1.90.0020.00517.37
8.1.80.0000.00717.50
8.1.70.0030.00317.43
8.1.60.0030.00717.61
8.1.50.0040.00817.47
8.1.40.0070.00317.47
8.1.30.0080.00017.52
8.1.20.0040.00417.52
8.1.10.0040.00417.48
8.1.00.0040.00417.43
8.0.300.0000.00718.77
8.0.290.0040.00417.18
8.0.280.0040.00418.46
8.0.270.0000.00717.29
8.0.260.0000.00717.18
8.0.250.0070.00016.83
8.0.240.0000.00717.00
8.0.230.0000.00716.91
8.0.220.0030.00316.98
8.0.210.0000.00716.91
8.0.200.0030.00316.87
8.0.190.0000.00716.91
8.0.180.0070.00016.91
8.0.170.0030.00616.93
8.0.160.0040.00416.79
8.0.150.0080.00016.71
8.0.140.0050.00316.90
8.0.130.0060.00013.35
8.0.120.0000.00816.89
8.0.110.0030.00516.82
8.0.100.0080.00016.74
8.0.90.0000.00716.79
8.0.80.0090.00616.94
8.0.70.0000.00716.95
8.0.60.0080.00016.86
8.0.50.0070.00016.74
8.0.30.0130.00717.30
8.0.20.0140.00517.40
8.0.10.0070.00016.90
8.0.00.0070.01016.74
7.4.330.0000.00515.05
7.4.320.0000.00916.60
7.4.300.0000.00616.54
7.4.290.0070.00016.62
7.4.280.0000.00716.57
7.4.270.0030.00316.59
7.4.260.0040.00716.61
7.4.250.0030.00516.56
7.4.240.0070.00016.59
7.4.230.0000.00716.36
7.4.220.0070.01316.60
7.4.210.0090.00616.53
7.4.200.0040.00416.41
7.4.190.0030.00316.43
7.4.160.0070.01016.63
7.4.150.0140.01117.40
7.4.140.0090.00917.86
7.4.130.0090.00816.43
7.4.120.0080.01116.56
7.4.110.0000.01616.46
7.4.100.0130.01016.41
7.4.90.0070.01016.62
7.4.80.0200.00619.39
7.4.70.0060.01016.47
7.4.60.0110.00716.55
7.4.50.0030.00616.23
7.4.40.0110.01116.42
7.4.30.0070.01016.63
7.4.00.0090.00615.21
7.3.330.0050.00013.46
7.3.320.0030.00313.26
7.3.310.0000.00716.40
7.3.300.0000.00816.39
7.3.290.0030.01116.40
7.3.280.0120.00816.38
7.3.270.0100.00717.40
7.3.260.0160.00716.38
7.3.250.0090.00916.57
7.3.240.0030.01516.48
7.3.230.0060.01016.45
7.3.210.0120.01216.54
7.3.200.0030.01519.39
7.3.190.0060.01616.38
7.3.180.0070.01016.58
7.3.170.0130.00316.36
7.3.160.0130.00316.64
7.3.120.0060.01014.98
7.3.10.0030.01016.26
7.3.00.0100.00716.07
7.2.330.0070.01016.58
7.2.320.0060.01216.85
7.2.310.0100.01316.49
7.2.300.0060.01216.84
7.2.290.0090.00916.82
7.2.130.0140.00316.38
7.2.120.0090.00616.83
7.2.110.0150.00016.83
7.2.100.0140.00316.66
7.2.90.0060.00916.48
7.2.80.0030.00916.48
7.2.70.0090.00616.74
7.2.60.0060.00916.69
7.2.50.0050.01316.95
7.2.40.0100.01016.90
7.2.30.0160.00016.86
7.2.20.0220.00816.93
7.2.10.0270.00016.99
7.2.00.0090.00718.21
7.1.250.0040.01315.75
7.1.100.0110.00017.98
7.1.70.0030.00717.09
7.1.60.0090.01619.46
7.1.50.0070.00416.96
7.1.00.0070.07322.51
7.0.200.0040.00416.55
7.0.140.0000.07722.18
7.0.60.0330.06720.05
7.0.50.0100.07317.90
7.0.40.0030.08020.13
7.0.30.0430.06720.09
7.0.20.0130.04720.28
7.0.10.0070.09320.06
7.0.00.0070.04020.20
5.6.280.0070.07021.12
5.6.210.0100.07320.74
5.6.200.0070.04018.22
5.6.190.0070.04320.61
5.6.180.0130.06020.47
5.6.170.0230.04720.46
5.6.160.0130.06720.54
5.6.150.0070.08718.13
5.6.140.0030.05318.28
5.6.130.0030.05018.19
5.6.120.0030.08021.04
5.6.110.0130.05020.91
5.6.100.0100.07321.04
5.6.90.0170.04021.13
5.6.80.0070.05320.42
5.5.350.0070.07320.32
5.5.340.0030.05018.05
5.5.330.0000.06020.21
5.5.320.0030.05020.25
5.5.310.0270.08320.32
5.5.300.0170.06018.09
5.5.290.0030.05017.97
5.5.280.0070.04320.91
5.5.270.0170.07720.99
5.5.260.0070.08720.94
5.5.250.0100.05320.63
5.5.240.0100.04320.29
5.4.450.0870.05719.48
5.4.440.0800.07319.61
5.4.430.0100.08319.20
5.4.420.0870.05719.48
5.4.410.0870.05319.50
5.4.400.0130.06019.11
5.4.390.0800.06319.21
5.4.380.0270.05718.74
5.4.370.0300.05718.59
5.4.360.0330.05018.74
5.4.350.0170.06718.77
5.4.340.0300.04318.49
5.4.320.0070.04612.52
5.4.310.0070.03612.52
5.4.300.0060.03512.52
5.4.290.0120.06212.51
5.4.280.0150.06012.41
5.4.270.0170.04912.41
5.4.260.0120.05612.41
5.4.250.0160.07412.41
5.4.240.0100.06812.41
5.4.230.0130.05612.40
5.4.220.0180.04912.40
5.4.210.0120.07612.40
5.4.200.0110.07912.40
5.4.190.0280.11312.40
5.4.180.0130.06012.40
5.4.170.0130.06012.41
5.4.160.0090.05812.40
5.4.150.0060.05712.40
5.4.140.0140.06612.08
5.4.130.0160.05412.07
5.4.120.0170.06712.03
5.4.110.0100.05112.02
5.4.100.0120.05212.02
5.4.90.0100.05612.02
5.4.80.0130.06812.02
5.4.70.0160.05912.02
5.4.60.0120.04812.02
5.4.50.0130.05212.02
5.4.40.0120.04312.01
5.4.30.0170.04412.00
5.4.20.0090.05212.00
5.4.10.0120.04712.00
5.4.00.0090.04811.49
5.3.290.0060.03812.80
5.3.280.0060.06412.71
5.3.270.0110.05612.72
5.3.260.0070.06212.72
5.3.250.0210.04812.72
5.3.240.0090.05212.72
5.3.230.0120.05612.71
5.3.220.0120.06212.68
5.3.210.0130.06312.68
5.3.200.0100.05612.68
5.3.190.0080.05812.68
5.3.180.0110.04612.67
5.3.170.0110.06512.67
5.3.160.0220.06212.67
5.3.150.0090.06212.68
5.3.140.0120.05812.66
5.3.130.0110.06112.66
5.3.120.0100.06012.66
5.3.110.0140.05612.66
5.3.100.0150.06112.15
5.3.90.0090.06612.13
5.3.80.0180.04812.13
5.3.70.0080.05812.13
5.3.60.0120.05512.11
5.3.50.0200.07412.05
5.3.40.0120.05212.05
5.3.30.0120.05812.01
5.3.20.0120.05711.79
5.3.10.0090.04911.76
5.3.00.0150.06411.75
5.2.170.0110.0579.24
5.2.160.0120.0329.24
5.2.150.0100.0519.24
5.2.140.0160.0399.23
5.2.130.0070.0449.20
5.2.120.0110.0419.20
5.2.110.0060.0379.20
5.2.100.0060.0559.19
5.2.90.0070.0389.20
5.2.80.0070.0519.19
5.2.70.0060.0419.19
5.2.60.0070.0449.15
5.2.50.0090.0429.12
5.2.40.0080.0389.09
5.2.30.0080.0379.06
5.2.20.0050.0389.05
5.2.10.0100.0358.96
5.2.00.0070.0408.82
5.1.60.0040.0358.11
5.1.50.0060.0328.11
5.1.40.0050.0338.09
5.1.30.0040.0308.43
5.1.20.0050.0308.45
5.1.10.0070.0348.18
5.1.00.0080.0358.19
5.0.50.0050.0236.66
5.0.40.0050.0256.53
5.0.30.0080.0366.33
5.0.20.0040.0276.30
5.0.10.0060.0286.28
5.0.00.0050.0376.27
4.4.90.0040.0174.78
4.4.80.0040.0214.75
4.4.70.0050.0184.76
4.4.60.0050.0184.75
4.4.50.0030.0184.77
4.4.40.0040.0264.71
4.4.30.0030.0194.76
4.4.20.0060.0184.84
4.4.10.0050.0164.85
4.4.00.0120.0224.76
4.3.110.0050.0224.67
4.3.100.0040.0224.67
4.3.90.0040.0224.63
4.3.80.0070.0274.58
4.3.70.0050.0174.63
4.3.60.0060.0184.63
4.3.50.0070.0204.63
4.3.40.0050.0314.54
4.3.30.0020.0233.30
4.3.20.0050.0133.28
4.3.10.0020.0223.23
4.3.00.0030.0279.00

preferences:
50.01 ms | 401 KiB | 5 Q