3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Atom; interface CollectionInterface extends \IteratorAggregate { /** * * @param \Atom\AggregatorInterface $aggregator * @return mixed */ function aggregate(\Atom\AggregatorInterface $aggregator); /** * * @param \Atom\EnumeratorInterface $enumerator * @return \Atom\CollectionInterface */ function enumerate(\Atom\EnumeratorInterface $enumerator); /** * * @return array */ function getArray(); } class Collection implements \Atom\CollectionInterface { /** * * @param mixed $iterable * @return \Atom\Collection */ public static function create($iterable) { if (is_array($iterable)) { return new \Atom\Collection(new \ArrayIterator($iterable)); } return new \Atom\Collection(new \IteratorIterator($iterable)); } /** * * @var \Iterator */ private $iterator; /** * * @param \Iterator $iterator */ public function __construct(\Iterator $iterator) { $this->iterator = $iterator; } /** * * @param \Atom\AggregatorInterface $aggregator * @return mixed */ public function aggregate(\Atom\AggregatorInterface $aggregator) { return $aggregator->aggregate($this); } /** * * @param \Atom\EnumeratorInterface $enumerator * @return \Atom\CollectionInterface */ public function enumerate(\Atom\EnumeratorInterface $enumerator) { return self::create($enumerator->enumerate($this)); } /** * * @return \Iterator */ public function getIterator() { return $this->iterator; } /** * * @return array */ public function getArray() { return iterator_to_array($this->iterator); } } interface EnumeratorInterface { /** * * @param \Atom\CollectionInterface $collection * @return mixed */ function enumerate(\Atom\CollectionInterface $collection); } interface AggregatorInterface { /** * * @param \Atom\CollectionInterface $collection * @return mixed */ function aggregate(\Atom\CollectionInterface $collection); } class MapEnumerator implements \Atom\EnumeratorInterface { /** * * @var callable */ private $function; /** * * @param callable $function */ public function __construct(callable $function) { $this->function = $function; } /** * * @param \Atom\CollectionInterface $collection * @return mixed */ public function enumerate(\Atom\CollectionInterface $collection) { $function = $this->function; foreach ($collection as $key => $value) { yield $key => $function($value, $key); } } } class FilterEnumerator implements \Atom\EnumeratorInterface { /** * * @var callable */ private $function; /** * * @param callable $function */ public function __construct(callable $function) { $this->function = $function; } /** * * @param \Atom\CollectionInterface $collection * @return mixed */ public function enumerate(\Atom\CollectionInterface $collection) { $function = $this->function; foreach ($collection as $key => $value) { if ($function($value, $key)) { yield $key => $value; } } } } class SumAggregator implements \Atom\AggregatorInterface { /** * * @param \Atom\CollectionInterface $collection * @return mixed */ public function aggregate(\Atom\CollectionInterface $collection) { return array_sum($collection->getArray()); } } $sum = \Collection::create([1, 2, 3, 4, 5])->enumerate(new \MapEnumerator(function ($value) { return $value * 3; }))->enumerate(new \FilterEnumerator(function ($value) { return $value % 2 == 0; }))->aggregate(new \SumAggregator()); var_dump($sum);

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.0180.00018.43
8.3.50.0110.00821.09
8.3.40.0140.00718.85
8.3.30.0070.00719.04
8.3.20.0070.00020.16
8.3.10.0040.00423.65
8.3.00.0050.00319.50
8.2.180.0040.01116.50
8.2.170.0140.00722.96
8.2.160.0140.00020.39
8.2.150.0040.00424.18
8.2.140.0030.00724.66
8.2.130.0040.00426.16
8.2.120.0080.00022.23
8.2.110.0040.00721.03
8.2.100.0080.00417.91
8.2.90.0000.00817.84
8.2.80.0040.00417.97
8.2.70.0050.00317.63
8.2.60.0090.00617.54
8.2.50.0040.00418.07
8.2.40.0000.00818.16
8.2.30.0070.00418.11
8.2.20.0050.00317.79
8.2.10.0000.00718.15
8.2.00.0040.00417.80
8.1.280.0100.00325.92
8.1.270.0040.00423.79
8.1.260.0040.00426.35
8.1.250.0050.00228.09
8.1.240.0000.00922.46
8.1.230.0080.00320.89
8.1.220.0000.00817.74
8.1.210.0040.00418.79
8.1.200.0040.00417.35
8.1.190.0050.00317.25
8.1.180.0030.00518.10
8.1.170.0040.00418.50
8.1.160.0000.00721.94
8.1.150.0000.00818.83
8.1.140.0040.00417.49
8.1.130.0000.00717.80
8.1.120.0000.00817.43
8.1.110.0040.00417.33
8.1.100.0000.00717.43
8.1.90.0040.00417.37
8.1.80.0000.00817.46
8.1.70.0000.00817.44
8.1.60.0050.00317.54
8.1.50.0030.00517.46
8.1.40.0040.00417.57
8.1.30.0000.00817.66
8.1.20.0040.00417.54
8.1.10.0000.00817.55
8.1.00.0030.00517.47
8.0.300.0000.00720.11
8.0.290.0000.00717.00
8.0.280.0070.00018.41
8.0.270.0000.00717.39
8.0.260.0030.00317.25
8.0.250.0030.00317.11
8.0.240.0000.00817.14
8.0.230.0080.00017.08
8.0.220.0040.00417.05
8.0.210.0000.00717.02
8.0.200.0030.00317.16
8.0.190.0040.00417.05
8.0.180.0000.00817.06
8.0.170.0040.00416.95
8.0.160.0000.00817.11
8.0.150.0070.00016.88
8.0.140.0030.00517.01
8.0.130.0000.00513.48
8.0.120.0050.00317.02
8.0.110.0050.00316.93
8.0.100.0000.00817.07
8.0.90.0040.00417.02
8.0.80.0100.00716.98
8.0.70.0040.00417.00
8.0.60.0040.00416.89
8.0.50.0040.00416.98
8.0.30.0080.01117.16
8.0.20.0130.00817.40
8.0.10.0080.00017.05
8.0.00.0080.01016.78
7.4.330.0030.00315.02
7.4.320.0060.00016.52
7.4.300.0000.00716.65
7.4.290.0080.00016.60
7.4.280.0070.00016.61
7.4.270.0050.00216.51
7.4.260.0040.00416.40
7.4.250.0000.00716.57
7.4.240.0040.00416.53
7.4.230.0000.00716.68
7.4.220.0110.00716.72
7.4.210.0070.01316.63
7.4.200.0000.00716.59
7.4.160.0030.01316.71
7.4.150.0090.00917.40
7.4.140.0090.00917.86
7.4.130.0120.00516.69
7.4.120.0160.00116.67
7.4.110.0050.01316.55
7.4.100.0090.00816.88
7.4.90.0070.01116.45
7.4.80.0130.00419.39
7.4.70.0090.00916.63
7.4.60.0030.01416.59
7.4.50.0040.00416.30
7.4.40.0070.01016.16
7.4.30.0040.01416.49
7.4.00.0070.01115.05
7.3.330.0000.00513.36
7.3.320.0050.00013.22
7.3.310.0030.00316.18
7.3.300.0030.00316.36
7.3.290.0090.00816.33
7.3.280.0070.00916.38
7.3.270.0100.01017.40
7.3.260.0040.01416.36
7.3.250.0110.00616.67
7.3.240.0140.00316.40
7.3.230.0050.01216.55
7.3.210.0120.01016.55
7.3.200.0150.00319.39
7.3.190.0080.01116.40
7.3.180.0100.00616.32
7.3.170.0090.01116.50
7.3.160.0150.00716.37
7.2.330.0090.01316.54
7.2.320.0030.01716.57
7.2.310.0090.00616.52
7.2.300.0100.00716.65
7.2.290.0070.01516.71
7.2.60.0080.00416.50
7.2.00.0090.00618.85
7.1.200.0090.00615.61
7.1.100.0040.01118.31
7.1.70.0040.00416.96
7.1.60.0090.01619.11
7.1.50.0100.01616.99
7.1.00.0100.07022.51
7.0.200.0000.01016.51
7.0.140.0030.06722.07
7.0.60.0030.07019.96
7.0.50.0130.05717.77
7.0.40.0030.05720.36
7.0.30.0130.06320.06
7.0.20.0170.08020.07
7.0.10.0130.08320.30
7.0.00.0130.04320.08
5.6.280.0030.07320.93
5.6.210.0200.04020.74
5.6.200.0030.05318.18
5.6.190.0130.06720.63
5.6.180.0230.08020.39
5.6.170.0300.07320.71
5.6.160.0000.05720.71
5.6.150.0030.04018.31
5.6.140.0100.05018.26
5.6.130.0030.06318.18
5.6.120.0030.08721.13
5.6.110.0100.07021.10
5.6.100.0100.07721.07
5.6.90.0070.07321.09
5.6.80.0170.07720.37
5.6.70.4370.03720.52
5.5.350.0230.06020.55
5.5.340.0070.05017.95
5.5.330.0100.06720.37
5.5.320.0330.07720.40
5.5.310.0200.04320.36
5.5.300.0100.06318.07
5.5.290.0030.04017.99
5.5.280.0170.07320.98
5.5.270.0030.05320.78
5.5.260.0070.05320.80
5.5.250.0100.03320.49
5.5.240.0100.03720.20
5.4.450.0770.05719.36
5.4.440.0630.06019.17
5.4.430.0930.04719.46
5.4.420.0700.05319.34
5.4.410.0870.05019.57
5.4.400.0800.04719.13
5.4.390.0570.05319.16
5.4.380.0370.06719.15
5.4.370.1000.05319.38
5.4.360.0600.06319.14
5.4.350.0630.04719.30
5.4.340.0090.03112.05
5.4.320.0050.03812.54
5.4.310.0050.03812.54
5.4.300.0040.03812.54
5.4.290.0110.03412.53
5.4.280.0040.03712.43
5.4.270.0040.03812.43
5.4.260.0060.03712.43
5.4.250.0070.03612.43
5.4.240.0100.03912.43
5.4.230.0060.03812.42
5.4.220.0090.03512.42
5.4.210.0070.03512.42
5.4.200.0090.03612.42
5.4.190.0070.03412.42
5.4.180.0090.03312.41
5.4.170.0080.03212.43
5.4.160.0050.03612.42
5.4.150.0040.03912.42
5.4.140.0060.03612.11
5.4.130.0060.04012.09
5.4.120.0060.03512.05
5.4.110.0040.03712.05
5.4.100.0080.03312.05
5.4.90.0080.03512.05
5.4.80.0100.03212.05
5.4.70.0050.03512.04
5.4.60.0060.03512.05
5.4.50.0040.03712.05
5.4.40.0030.03712.03
5.4.30.0050.03612.03
5.4.20.0060.03512.03
5.4.10.0050.03512.03
5.4.00.0060.03811.53
5.3.290.0100.03712.80
5.3.280.0090.04012.72
5.3.270.0030.04212.73
5.3.260.0050.04012.73
5.3.250.0080.04812.73
5.3.240.0060.03612.73
5.3.230.0090.03512.72
5.3.220.0050.03812.70
5.3.210.0070.04112.70
5.3.200.0090.03412.70
5.3.190.0070.03712.70
5.3.180.0100.03312.69
5.3.170.0100.04012.69
5.3.160.0070.04212.69
5.3.150.0070.04812.69
5.3.140.0100.04812.69
5.3.130.0080.03912.68
5.3.120.0040.04112.68
5.3.110.0040.04212.68
5.3.100.0080.03712.16
5.3.90.0070.03612.15
5.3.80.0060.03612.14
5.3.70.0070.04012.14
5.3.60.0050.03712.12
5.3.50.0030.03912.07
5.3.40.0080.03512.07
5.3.30.0070.03712.03
5.3.20.0030.03911.82
5.3.10.0080.03311.77
5.3.00.0070.03611.76
5.2.170.0070.0399.18
5.2.160.0080.0379.19
5.2.150.0070.0299.18
5.2.140.0020.0339.18
5.2.130.0070.0319.14
5.2.120.0100.0269.14
5.2.110.0060.0329.15
5.2.100.0050.0349.14
5.2.90.0060.0309.14
5.2.80.0050.0369.14
5.2.70.0060.0309.14
5.2.60.0060.0299.09
5.2.50.0060.0289.06
5.2.40.0050.0289.04
5.2.30.0060.0299.02
5.2.20.0030.0309.01
5.2.10.0030.0308.93
5.2.00.0070.0298.79
5.1.60.0050.0278.07
5.1.50.0050.0248.06
5.1.40.0050.0278.05
5.1.30.0040.0278.40
5.1.20.0030.0288.43
5.1.10.0050.0248.15
5.1.00.0020.0278.14
5.0.50.0020.0216.63
5.0.40.0050.0176.48
5.0.30.0010.0336.29
5.0.20.0040.0186.27
5.0.10.0030.0206.24
5.0.00.0030.0306.23
4.4.90.0040.0134.78
4.4.80.0020.0164.75
4.4.70.0050.0124.75
4.4.60.0050.0124.75
4.4.50.0010.0174.77
4.4.40.0030.0244.71
4.4.30.0030.0144.75
4.4.20.0050.0154.84
4.4.10.0020.0174.85
4.4.00.0020.0264.75
4.3.110.0030.0164.67
4.3.100.0020.0164.67
4.3.90.0040.0144.63
4.3.80.0020.0244.58
4.3.70.0020.0154.63
4.3.60.0010.0164.63
4.3.50.0040.0144.63
4.3.40.0010.0284.54
4.3.30.0050.0173.29
4.3.20.0030.0143.27
4.3.10.0010.0163.22
4.3.00.0100.0206.75

preferences:
36.76 ms | 401 KiB | 5 Q