3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BeforeAfterIterator implements Iterator { private $iterator; public function __construct(iterable $iterator, $before, $after) { if (!$iterator instanceof Iterator) { $iterator = (function ($iterable) { yield from $iterable; })($iterator); } if ($iterator->valid()) { $this->iterator = new AppendIterator(); $this->iterator->append(new ArrayIterator([$before])); $this->iterator->append($iterator); $this->iterator->append(new ArrayIterator([$after])); } else { $this->iterator = new ArrayIterator([]); } } 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(); } } $begin = new DateTime('2020-02-01'); $end = new DateTime('2020-02-29'); $interval = new DateInterval('P1D'); $daterange = new DatePeriod($begin, $interval ,$end); foreach (new BeforeAfterIterator($daterange, new \DateTime('2020-01-31'), new \DateTime('2020-03-01')) as $value) { echo $value->format('Y-m-d'), PHP_EOL; } foreach (new BeforeAfterIterator(range(1, 10), 'Before', 'After') as $value) { echo $value, PHP_EOL; } function generator() { yield from [1, 2, 3, 4, 5]; } foreach (new BeforeAfterIterator(generator(), 'Before', 'After') as $value) { echo $value, PHP_EOL; }

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.4.20.0100.01020.01
8.4.10.0060.00318.12
8.3.150.0090.00920.81
8.3.140.0060.00317.10
8.3.130.0090.00618.59
8.3.120.0080.00019.29
8.3.110.0080.00820.94
8.3.100.0000.00918.84
8.3.90.0040.00416.88
8.3.80.0030.00617.97
8.3.70.0080.00816.88
8.3.60.0160.00618.68
8.3.50.0100.00523.82
8.3.40.0090.00619.09
8.3.30.0120.00318.79
8.3.20.0040.00421.02
8.3.10.0030.00520.35
8.3.00.0050.00220.64
8.2.270.0090.01217.60
8.2.260.0040.00418.86
8.2.250.0110.00716.89
8.2.240.0040.00417.41
8.2.230.0040.00422.58
8.2.220.0040.00424.06
8.2.210.0070.00326.77
8.2.200.0040.00416.75
8.2.190.0170.00717.00
8.2.180.0110.00618.54
8.2.170.0090.00922.96
8.2.160.0060.00922.96
8.2.150.0080.00025.66
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0040.01119.89
8.2.110.0000.00920.85
8.2.100.0090.00318.03
8.2.90.0050.00319.25
8.2.80.0060.00317.97
8.2.70.0060.00317.75
8.2.60.0030.00617.93
8.2.50.0040.00418.07
8.2.40.0030.00518.02
8.2.30.0040.00419.41
8.2.20.0050.00218.22
8.2.10.0000.00719.38
8.2.00.0050.00219.25
8.1.310.0050.00318.36
8.1.300.0000.00819.96
8.1.290.0060.00318.88
8.1.280.0040.01825.92
8.1.270.0040.00422.04
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00622.18
8.1.230.0070.00717.70
8.1.220.0000.00917.91
8.1.210.0050.00318.77
8.1.200.0090.00017.60
8.1.190.0000.00917.48
8.1.180.0060.00318.10
8.1.170.0000.00818.56
8.1.160.0060.00319.20
8.1.150.0000.00719.10
8.1.140.0050.00320.79
8.1.130.0060.00320.19
8.1.120.0000.00817.68
8.1.110.0060.00317.61
8.1.100.0000.00817.75
8.1.90.0040.00417.71
8.1.80.0040.00417.77
8.1.70.0050.00317.70
8.1.60.0040.00417.77
8.1.50.0000.00817.71
8.1.40.0000.00917.71
8.1.30.0000.00817.67
8.1.20.0000.00917.81
8.1.10.0030.00517.66
8.1.00.0040.00417.69
8.0.300.0040.00418.77
8.0.290.0030.00617.13
8.0.280.0000.00718.45
8.0.270.0030.00318.32
8.0.260.0030.00520.09
8.0.250.0030.00317.30
8.0.240.0030.00717.14
8.0.230.0030.00517.23
8.0.220.0000.00717.12
8.0.210.0080.00017.25
8.0.200.0050.00217.17
8.0.190.0030.00617.26
8.0.180.0000.00817.28
8.0.170.0030.00617.13
8.0.160.0080.00017.22
8.0.150.0080.00017.11
8.0.140.0040.00417.07
8.0.130.0000.00613.60
8.0.120.0040.00417.17
8.0.110.0000.00817.08
8.0.100.0060.00317.26
8.0.90.0090.00017.14
8.0.80.0140.00817.19
8.0.70.0050.00317.04
8.0.60.0000.00817.16
8.0.50.0040.00417.08
8.0.30.0120.00817.47
8.0.20.0080.01617.26
8.0.10.0000.00817.14
8.0.00.0040.01616.92
7.4.330.0050.00015.55
7.4.320.0060.00016.81
7.4.300.0000.00616.69
7.4.290.0070.00016.75
7.4.280.0050.00516.77
7.4.270.0030.00316.66
7.4.260.0030.00313.40
7.4.250.0040.00416.79
7.4.240.0040.00316.64
7.4.230.0050.00216.78
7.4.220.0010.00616.78
7.4.210.0050.00916.71
7.4.200.0000.00716.82
7.4.130.0080.01416.83
7.4.120.0090.01516.59
7.4.110.0000.01716.74
7.4.100.0150.00316.80
7.4.90.0130.00316.93
7.4.80.0070.01719.39
7.4.70.0090.00616.88
7.4.60.0070.01016.80
7.4.50.0060.00916.75
7.4.40.0070.01016.75
7.4.30.0080.01016.45
7.4.20.0070.01016.60
7.4.10.0110.01116.44
7.4.00.0090.00916.75
7.3.330.0030.00316.63
7.3.320.0000.00513.39
7.3.310.0040.00416.61
7.3.300.0000.00716.57
7.3.290.0080.00716.52
7.3.260.0110.01016.77
7.3.240.0110.00816.58
7.3.230.0130.01016.66
7.3.210.0090.00916.65
7.3.200.0070.01016.85
7.3.190.0140.00316.69
7.3.180.0060.01216.72
7.3.170.0140.00716.49
7.3.160.0130.00316.88
7.3.150.0150.00616.68
7.3.140.0030.01316.52
7.3.130.0120.00916.48
7.3.120.0100.01316.74
7.3.110.0080.01716.76
7.3.100.0060.00916.58
7.3.90.0180.00416.55
7.3.80.0140.00716.47
7.3.70.0120.01116.51
7.3.60.0160.00616.65
7.3.50.0110.01116.61
7.3.40.0110.00716.61
7.3.30.0000.01616.46
7.3.20.0150.00916.44
7.3.10.0120.00616.44
7.3.00.0040.01216.51
7.2.330.0060.01316.65
7.2.320.0000.01816.78
7.2.310.0120.00617.06
7.2.300.0120.00916.81
7.2.290.0150.00417.07
7.2.280.0070.01016.70
7.2.270.0070.01016.81
7.2.260.0060.01216.93
7.2.250.0130.00916.74
7.2.240.0120.00416.76
7.2.230.0070.01016.86
7.2.220.0100.01216.91
7.2.210.0080.01616.75
7.2.200.0070.01016.81
7.2.190.0150.00816.85
7.2.180.0080.01416.73
7.2.170.0120.00616.85
7.2.160.0090.01516.70
7.2.150.0150.01216.81
7.2.140.0150.00616.80
7.2.130.0100.01316.78
7.2.120.0060.01216.90
7.2.110.0090.00916.84
7.2.100.0060.01216.80
7.2.90.0100.00916.64
7.2.80.0030.01316.77
7.2.70.0130.00616.86
7.2.60.0100.00716.91
7.2.50.0070.01016.80
7.2.40.0070.01317.03
7.2.30.0110.00716.75
7.2.20.0130.01016.79
7.2.10.0160.00616.75
7.2.00.0060.01616.80

preferences:
133.29 ms | 403 KiB | 5 Q