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 = \Atom\Collection::create([1, 2, 3, 4, 5])->enumerate(new \Atom\MapEnumerator(function ($value) { return $value * 3; }))->enumerate(new \Atom\FilterEnumerator(function ($value) { return $value % 2 == 0; }))->aggregate(new \Atom\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.0140.00418.43
8.3.50.0120.00921.15
8.3.40.0140.00418.84
8.3.30.0120.00819.27
8.3.20.0000.00720.33
8.3.10.0060.00323.48
8.3.00.0040.00419.27
8.2.180.0120.00318.42
8.2.170.0090.01222.96
8.2.160.0100.00320.35
8.2.150.0000.00824.18
8.2.140.0070.00324.66
8.2.130.0060.00326.16
8.2.120.0040.00419.77
8.2.110.0050.00520.86
8.2.100.0040.00817.79
8.2.90.0030.00617.82
8.2.80.0000.00817.97
8.2.70.0040.00417.63
8.2.60.0040.00717.91
8.2.50.0040.00418.07
8.2.40.0060.00318.22
8.2.30.0090.00018.02
8.2.20.0000.00817.62
8.2.10.0040.00417.99
8.2.00.0050.00317.72
8.1.280.0090.00625.92
8.1.270.0060.00322.14
8.1.260.0020.00526.35
8.1.250.0070.00028.09
8.1.240.0060.00322.57
8.1.230.0090.00320.87
8.1.220.0040.00417.74
8.1.210.0100.00018.80
8.1.200.0030.00717.35
8.1.190.0000.00817.23
8.1.180.0030.00518.10
8.1.170.0040.00418.52
8.1.160.0040.00422.08
8.1.150.0050.00318.82
8.1.140.0000.00717.42
8.1.130.0030.00317.89
8.1.120.0020.00517.49
8.1.110.0030.00517.39
8.1.100.0000.00717.45
8.1.90.0040.00417.39
8.1.80.0040.00417.46
8.1.70.0070.00017.39
8.1.60.0000.00917.59
8.1.50.0040.00417.42
8.1.40.0000.00817.48
8.1.30.0040.00417.61
8.1.20.0040.00417.71
8.1.10.0000.00817.56
8.1.00.0040.00417.54
8.0.300.0080.00020.07
8.0.290.0030.00516.63
8.0.280.0000.00718.58
8.0.270.0030.00317.19
8.0.260.0040.00417.34
8.0.250.0030.00317.14
8.0.240.0030.00317.11
8.0.230.0070.00016.97
8.0.220.0000.00717.00
8.0.210.0050.00317.02
8.0.200.0000.00617.16
8.0.190.0090.00016.99
8.0.180.0000.00817.01
8.0.170.0000.00817.09
8.0.160.0030.00517.00
8.0.150.0000.00717.00
8.0.140.0000.00716.99
8.0.130.0000.00513.48
8.0.120.0000.00717.00
8.0.110.0030.00616.94
8.0.100.0050.00317.16
8.0.90.0000.00816.91
8.0.80.0160.00617.02
8.0.70.0040.00416.92
8.0.60.0040.00417.02
8.0.50.0000.00817.04
8.0.30.0060.01417.06
8.0.20.0120.01017.40
8.0.10.0040.00416.99
8.0.00.0090.01116.79
7.4.330.0040.00415.02
7.4.320.0000.00716.58
7.4.300.0040.00416.63
7.4.290.0030.00316.68
7.4.280.0000.00816.61
7.4.270.0050.00216.72
7.4.260.0030.00316.66
7.4.250.0000.00716.54
7.4.240.0040.00416.67
7.4.230.0030.00316.38
7.4.220.0120.00616.68
7.4.210.0090.00916.68
7.4.200.0070.00016.58
7.4.160.0100.00716.57
7.4.150.0060.01417.40
7.4.140.0120.00617.86
7.4.130.0110.00616.69
7.4.120.0060.01216.48
7.4.110.0060.01116.78
7.4.100.0100.00716.52
7.4.90.0130.00416.53
7.4.80.0070.01419.39
7.4.70.0070.01116.68
7.4.60.0100.00716.52
7.4.50.0040.00416.51
7.4.40.0000.02116.41
7.4.30.0060.01516.66
7.4.10.0090.00915.25
7.4.00.0080.00814.88
7.3.330.0050.00013.27
7.3.320.0050.00013.43
7.3.310.0000.00716.44
7.3.300.0070.00016.35
7.3.290.0070.00716.41
7.3.280.0140.00516.43
7.3.270.0090.00917.40
7.3.260.0070.01016.44
7.3.250.0120.00516.68
7.3.240.0140.00716.47
7.3.230.0100.01016.58
7.3.210.0040.01216.48
7.3.200.0030.01319.39
7.3.190.0060.01216.67
7.3.180.0030.01316.43
7.3.170.0070.01016.45
7.3.160.0110.00716.58
7.3.130.0060.01214.81
7.3.120.0030.01215.11
7.3.110.0000.01514.75
7.3.100.0000.01514.57
7.3.90.0080.00814.88
7.3.80.0070.01015.22
7.3.70.0100.00314.70
7.3.60.0070.01014.86
7.3.50.0090.00614.91
7.3.40.0110.01114.73
7.3.30.0090.00614.84
7.3.20.0100.00716.55
7.3.10.0070.01016.50
7.3.00.0110.00416.83
7.2.330.0100.01016.53
7.2.320.0150.00316.91
7.2.310.0100.00716.94
7.2.300.0070.01016.63
7.2.290.0130.00916.57
7.2.260.0030.01414.77
7.2.250.0080.01215.18
7.2.240.0000.01514.77
7.2.230.0100.00715.27
7.2.220.0090.00615.33
7.2.210.0060.00815.22
7.2.200.0000.01515.15
7.2.190.0030.00715.04
7.2.180.0100.01015.19
7.2.170.0060.01115.01
7.2.160.0050.00814.99
7.2.150.0070.01017.06
7.2.140.0090.00616.89
7.2.130.0000.01316.84
7.2.120.0060.01016.71
7.2.110.0040.01516.96
7.2.100.0040.01416.90
7.2.90.0130.00017.15
7.2.80.0080.00816.91
7.2.70.0070.00717.04
7.2.60.0080.00417.05
7.2.50.0140.00416.93
7.2.40.0080.00817.14
7.2.30.0070.00717.01
7.2.20.0100.00716.77
7.2.10.0030.00717.06
7.2.00.0040.00818.07
7.1.330.0000.01415.64
7.1.320.0030.01015.86
7.1.310.0060.00915.52
7.1.300.0030.01715.79
7.1.290.0090.00615.50
7.1.280.0100.00015.80
7.1.270.0070.00715.95
7.1.260.0070.00715.62
7.1.250.0060.01015.96
7.1.240.0060.00615.76
7.1.230.0030.01415.75
7.1.220.0030.00915.85
7.1.210.0030.01015.72
7.1.200.0040.01215.77
7.1.190.0060.00915.94
7.1.180.0000.01715.59
7.1.170.0070.00715.40
7.1.160.0040.00415.75
7.1.150.0090.00615.54
7.1.140.0110.00415.72
7.1.130.0030.01015.93
7.1.120.0070.01015.86
7.1.110.0080.00815.73
7.1.100.0030.01117.04
7.1.90.0060.00915.57
7.1.80.0050.00515.88
7.1.70.0030.00816.21
7.1.60.0070.01417.53
7.1.50.0090.01116.28
7.1.40.0030.01315.72
7.1.30.0040.01115.55
7.1.20.0060.00615.52
7.1.10.0040.01115.77
7.1.00.0060.04319.00
7.0.330.0030.00815.54
7.0.320.0040.01115.63
7.0.310.0040.00815.27
7.0.300.0060.01015.30
7.0.290.0070.01015.38
7.0.280.0040.01215.41
7.0.270.0100.00315.34
7.0.260.0090.00015.35
7.0.250.0000.01515.52
7.0.240.0030.01315.44
7.0.230.0080.00415.28
7.0.220.0070.00715.51
7.0.210.0090.00415.61
7.0.200.0030.00516.11
7.0.190.0100.00715.40
7.0.180.0080.00815.55
7.0.170.0060.01015.50
7.0.160.0090.00615.54
7.0.150.0040.01515.39
7.0.140.0080.03818.82
7.0.130.0030.01015.60
7.0.120.0060.00915.57
7.0.110.0090.00915.57
7.0.100.0070.01115.50
7.0.90.0070.01015.20
7.0.80.0050.00515.60
7.0.70.0030.00615.24
7.0.60.0080.03717.69
7.0.50.0070.04716.76
7.0.40.0050.03416.95
7.0.30.0220.03916.86
7.0.20.0180.04316.75
7.0.10.0050.03216.89
7.0.00.0050.03316.79
5.6.400.0060.00614.51
5.6.390.0000.01814.14
5.6.380.0070.00714.23
5.6.370.0060.00314.23
5.6.360.0000.01314.22
5.6.350.0000.00914.44
5.6.340.0030.00614.04
5.6.330.0030.01214.53
5.6.320.0060.00914.10
5.6.310.0060.00814.48
5.6.300.0000.01514.61
5.6.290.0040.00814.64
5.6.280.0080.03717.55
5.6.270.0060.00914.23
5.6.260.0140.00414.28
5.6.250.0070.01014.57
5.6.240.0090.00614.37
5.6.230.0040.01114.48
5.6.220.0030.00714.61
5.6.210.0030.04917.65
5.6.200.0050.04816.41
5.6.190.0070.04817.43
5.6.180.0100.02917.40
5.6.170.0170.03417.37
5.6.160.0070.02817.46
5.6.150.0070.03216.45
5.6.140.0080.04416.33
5.6.130.0060.02816.41
5.6.120.0050.04517.63
5.6.110.0080.04717.79
5.6.100.0080.04217.68
5.6.90.0050.05017.93
5.6.80.0140.03717.37
5.6.70.1800.02517.58
5.6.60.0040.00714.29
5.6.50.0070.00714.25
5.6.40.0110.00714.45
5.6.30.0100.00714.62
5.6.20.0090.00614.23
5.6.10.0040.01114.45
5.6.00.0130.00014.27
5.5.380.0110.00414.23
5.5.370.0030.01014.52
5.5.360.0040.01114.25
5.5.350.0130.03517.32
5.5.340.0070.04016.07
5.5.330.0100.04517.34
5.5.320.0150.03717.26
5.5.310.0170.02017.21
5.5.300.0070.02316.00
5.5.290.0050.02416.21
5.5.280.0070.03117.46
5.5.270.0100.04117.56
5.5.260.0160.03317.35
5.5.250.0120.04217.50
5.5.240.0220.03517.22
5.5.230.0090.00013.99
5.5.220.0030.01314.02
5.5.210.0100.00314.27
5.5.200.0050.00514.30
5.5.190.0080.00614.35
5.5.180.0070.00714.57
5.5.170.0070.00714.10
5.5.160.0030.00814.07
5.5.150.0070.01114.27
5.5.140.0040.01114.14
5.5.130.0090.00614.45
5.5.120.0030.00614.34
5.5.110.0000.01514.52
5.5.100.0060.00914.56
5.5.90.0090.00314.37
5.5.80.0060.00614.39
5.5.70.0030.00614.52
5.5.60.0130.00314.36
5.5.50.0060.00614.18
5.5.40.0030.00714.23
5.5.30.0030.00614.43
5.5.20.0040.01114.50
5.5.10.0000.01014.46
5.5.00.0050.00514.18
5.4.450.0390.02916.22
5.4.440.0380.02916.28
5.4.430.0320.03516.33
5.4.420.0400.03616.27
5.4.410.0450.03016.00
5.4.400.0490.02716.06
5.4.390.0380.02816.04
5.4.380.0340.03416.01
5.4.370.0440.02615.99
5.4.360.0330.02915.90
5.4.350.0420.02716.12
5.4.340.0050.01812.51
5.4.330.0070.00312.97
5.4.320.0050.01912.75
5.4.310.0040.02512.75
5.4.300.0050.02312.75
5.4.290.0080.01912.75
5.4.280.0050.02012.70
5.4.270.0050.02012.70
5.4.260.0040.02212.70
5.4.250.0050.02112.70
5.4.240.0020.02212.70
5.4.230.0030.02212.70
5.4.220.0050.02012.70
5.4.210.0060.01912.70
5.4.200.0060.02312.70
5.4.190.0070.01912.69
5.4.180.0050.02212.69
5.4.170.0040.02412.70
5.4.160.0040.02112.69
5.4.150.0080.01612.69
5.4.140.0080.02012.54
5.4.130.0050.01912.53
5.4.120.0040.02212.51
5.4.110.0050.02012.51
5.4.100.0040.02112.51
5.4.90.0020.02512.51
5.4.80.0050.02412.51
5.4.70.0060.02112.51
5.4.60.0080.01712.51
5.4.50.0090.02312.51
5.4.40.0060.02012.50
5.4.30.0040.02112.50
5.4.20.0080.01812.50
5.4.10.0060.01912.50
5.4.00.0020.02512.24
5.3.290.0100.03512.80
5.3.280.0020.04312.72
5.3.270.0090.04412.73
5.3.260.0100.03512.73
5.3.250.0060.03712.73
5.3.240.0060.03712.73
5.3.230.0040.04012.72
5.3.220.0050.04112.69
5.3.210.0050.03912.70
5.3.200.0060.03712.69
5.3.190.0050.03912.70
5.3.180.0060.03512.69
5.3.170.0020.03912.68
5.3.160.0060.03612.69
5.3.150.0040.03912.69
5.3.140.0040.03812.68
5.3.130.0070.03712.68
5.3.120.0040.04012.67
5.3.110.0080.03712.68
5.3.100.0030.04012.16
5.3.90.0070.03512.15
5.3.80.0050.03712.13
5.3.70.0050.03812.13
5.3.60.0120.03012.12
5.3.50.0040.03812.06
5.3.40.0060.03612.06
5.3.30.0080.03412.03
5.3.20.0050.03611.80
5.3.10.0040.03611.77
5.3.00.0060.03611.76
5.2.170.0060.0299.19
5.2.160.0050.0299.18
5.2.150.0060.0309.18
5.2.140.0050.0299.18
5.2.130.0020.0319.14
5.2.120.0020.0319.14
5.2.110.0070.0269.15
5.2.100.0050.0289.14
5.2.90.0090.0259.15
5.2.80.0060.0289.14
5.2.70.0060.0289.14
5.2.60.0060.0289.09
5.2.50.0050.0299.06
5.2.40.0050.0289.04
5.2.30.0080.0269.02
5.2.20.0050.0289.01
5.2.10.0050.0288.93
5.2.00.0060.0278.79
5.1.60.0030.0258.07
5.1.50.0040.0258.07
5.1.40.0040.0248.05
5.1.30.0020.0288.40
5.1.20.0030.0278.42
5.1.10.0060.0238.14
5.1.00.0020.0348.14
5.0.50.0060.0186.63
5.0.40.0040.0186.48
5.0.30.0020.0336.30
5.0.20.0030.0196.27
5.0.10.0040.0196.25
5.0.00.0030.0306.24
4.4.90.0050.0134.78
4.4.80.0050.0124.75
4.4.70.0020.0164.76
4.4.60.0080.0104.76
4.4.50.0050.0134.77
4.4.40.0040.0234.71
4.4.30.0030.0164.76
4.4.20.0020.0164.84
4.4.10.0030.0164.85
4.4.00.0050.0224.76
4.3.110.0020.0164.67
4.3.100.0060.0124.66
4.3.90.0030.0144.63
4.3.80.0020.0244.58
4.3.70.0030.0134.63
4.3.60.0030.0144.63
4.3.50.0020.0164.62
4.3.40.0040.0234.54
4.3.30.0020.0163.28
4.3.20.0010.0173.27
4.3.10.0040.0133.22
4.3.00.0170.0176.91

preferences:
45.91 ms | 401 KiB | 5 Q