3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* span :: (a -> Bool) -> [a] -> ([a],[a]) span _ xs@[] = (xs, xs) span p xs@(x:xs') | p x = let (ys,zs) = span p xs' in (x:ys,zs) | otherwise = ([],xs) */ function span($p, $xs) { if (empty($xs)) { return [[], []]; } $xs_ = $xs; $x = array_shift($xs_); if ($p($x)) { list($ys, $zs) = span($p, $xs_); return [array_merge([$x], $ys), $zs]; } return [[], $xs]; } /* groupBy :: (a -> a -> Bool) -> [a] -> [[a]] groupBy _ [] = [] groupBy eq (x:xs) = (x:ys) : groupBy eq zs where (ys,zs) = span (eq x) xs */ function array_group(callable $eq, array $xs) { if (empty($xs)) { return []; } $x = array_shift($xs); // curry of $eq $eqx = function ($y) use ($eq, $x) { return $eq($x, $y); }; list($ys, $zs) = span($eqx, $xs); return array_merge([array_merge([$x], $ys)], array_group($eq, $zs)); } function it($m,$p){echo ($p?'OK':'NO')." It $m\n"; if(!$p){$GLOBALS['f']=1;}}function done(){if(@$GLOBALS['f'])die(1);} it('spans elements which match', span(function ($x) { return $x < 3; }, [1, 2, 3]) === [[1, 2], [3]]); it('spans elements which match from the start', span(function ($x) { return $x == 3; }, [1, 6, 3, 3]) === [[], [1, 2, 3, 3]]); it('spans returns empty lists on empty list', span(function ($x) { return false; }, []) === [[], []]); it('groups elements recursively', array_group(function ($a, $b) { return $a === $b; }, [1, 1, 2, 1]) === [[1, 1], [2], [1]]);

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.0100.00718.56
8.3.50.0150.00521.01
8.3.40.0070.00718.84
8.3.30.0070.00719.08
8.3.20.0030.00520.37
8.3.10.0050.00323.53
8.3.00.0040.00419.38
8.2.180.0100.01016.75
8.2.170.0040.01122.96
8.2.160.0070.00720.40
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0050.00322.11
8.2.110.0070.00321.04
8.2.100.0090.00319.76
8.2.90.0030.00519.35
8.2.80.0030.00517.97
8.2.70.0040.00417.50
8.2.60.0080.00017.93
8.2.50.0060.00318.07
8.2.40.0080.00018.35
8.2.30.0000.00818.08
8.2.20.0000.00817.70
8.2.10.0040.00418.22
8.2.00.0040.00417.71
8.1.280.0180.00325.92
8.1.270.0000.00822.20
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0070.01120.85
8.1.230.0070.00422.20
8.1.220.0070.00317.74
8.1.210.0050.00318.77
8.1.200.0030.00717.35
8.1.190.0040.00817.23
8.1.180.0030.00618.10
8.1.170.0040.00418.66
8.1.160.0040.00418.88
8.1.150.0050.00318.86
8.1.140.0040.00417.54
8.1.130.0030.00320.24
8.1.120.0080.00017.43
8.1.110.0000.00817.49
8.1.100.0070.00017.46
8.1.90.0020.00517.50
8.1.80.0070.00017.46
8.1.70.0070.00017.46
8.1.60.0040.00417.54
8.1.50.0000.00817.42
8.1.40.0070.00017.55
8.1.30.0000.00817.74
8.1.20.0090.00017.69
8.1.10.0000.00817.63
8.1.00.0020.00517.44
8.0.300.0040.00418.77
8.0.290.0040.00416.88
8.0.280.0080.00018.54
8.0.270.0040.00417.38
8.0.260.0000.00718.49
8.0.250.0030.00316.99
8.0.240.0060.00016.99
8.0.230.0000.00717.08
8.0.220.0030.00316.88
8.0.210.0000.00717.07
8.0.200.0000.00617.11
8.0.190.0000.00817.09
8.0.180.0040.00416.93
8.0.170.0040.00417.00
8.0.160.0050.00217.03
8.0.150.0070.00016.95
8.0.140.0080.00016.96
8.0.130.0030.00313.46
8.0.120.0040.00417.04
8.0.110.0040.00416.91
8.0.100.0040.00416.81
8.0.90.0040.00416.99
8.0.80.0080.01317.07
8.0.70.0020.00516.87
8.0.60.0000.00716.89
8.0.50.0040.00416.97
8.0.30.0130.00717.03
8.0.20.0050.01517.40
8.0.10.0030.00517.03
8.0.00.0080.01116.74
7.4.330.0030.00315.02
7.4.320.0030.00816.55
7.4.300.0050.00216.67
7.4.290.0070.00016.47
7.4.280.0070.00016.55
7.4.270.0040.00416.61
7.4.260.0030.00316.54
7.4.250.0040.00416.48
7.4.240.0020.00516.60
7.4.230.0020.00516.67
7.4.220.0040.01616.62
7.4.210.0070.00616.74
7.4.200.0070.00016.61
7.4.160.0100.01016.52
7.4.150.0100.01717.40
7.4.140.0130.01017.86
7.4.130.0100.00816.56
7.4.120.0100.01016.68
7.4.110.0060.01116.39
7.4.100.0110.00716.57
7.4.90.0120.00616.55
7.4.80.0130.00919.39
7.4.70.0060.00916.69
7.4.60.0090.00916.73
7.4.50.0050.00316.61
7.4.40.0090.00916.52
7.4.30.0090.00916.39
7.4.00.0030.00614.96
7.3.330.0050.00013.35
7.3.320.0000.00613.27
7.3.310.0000.00816.43
7.3.300.0000.00716.27
7.3.290.0080.00616.42
7.3.280.0120.00716.38
7.3.270.0100.00717.40
7.3.260.0110.00716.63
7.3.250.0090.00816.44
7.3.240.0140.00316.42
7.3.230.0130.00316.39
7.3.210.0070.01016.52
7.3.200.0000.01619.39
7.3.190.0140.00716.54
7.3.180.0090.00916.54
7.3.170.0120.00616.65
7.3.160.0110.00416.43
7.3.10.0060.00616.45
7.3.00.0130.00016.68
7.2.330.0110.00716.75
7.2.320.0120.00616.89
7.2.310.0060.01316.87
7.2.300.0140.00816.44
7.2.290.0000.02216.77
7.2.130.0000.01116.92
7.2.120.0060.00616.94
7.2.110.0130.00316.75
7.2.100.0040.00717.02
7.2.90.0060.00617.02
7.2.80.0060.00516.80
7.2.70.0120.00316.80
7.2.60.0050.00916.94
7.2.50.0070.00516.87
7.2.40.0080.00616.75
7.2.30.0100.00316.86
7.2.20.0080.00716.73
7.2.10.0070.00716.91
7.2.00.0130.00017.07
7.1.250.0080.00415.84
7.1.200.0000.01015.67
7.1.70.0020.00516.96
7.1.60.0060.00617.38
7.1.50.0120.01516.83
7.1.00.0030.07722.47
7.0.200.0070.01016.64
7.0.140.0000.07722.14
7.0.60.0100.03320.03
7.0.50.0070.08317.83
7.0.40.0030.04320.32
7.0.30.0270.03020.07
7.0.20.0130.06020.10
7.0.10.0070.09320.16
7.0.00.0100.07320.29
5.6.280.0000.07721.04
5.6.210.0200.05320.55
5.6.200.0030.05318.19
5.6.190.0030.04320.48
5.6.180.0300.08020.48
5.6.170.0200.04720.47
5.6.160.0030.07320.54
5.6.150.0100.07018.29
5.6.140.0070.04318.14
5.6.130.0070.07318.29
5.6.120.0200.07321.14
5.6.110.0100.04021.16
5.6.100.0070.08021.06
5.6.90.0070.04021.00
5.6.80.0100.07720.43
5.6.70.4330.04020.41
5.5.350.0100.07320.52
5.5.340.0030.04018.05
5.5.330.0030.06020.35
5.5.320.0300.07720.30
5.5.310.0230.05720.27
5.5.300.0000.09318.09
5.5.290.0130.03018.09
5.5.280.0100.09020.87
5.5.270.0100.05020.87
5.5.260.0130.03320.79
5.5.250.0100.03320.68
5.5.240.0270.05020.29
5.4.450.0770.06719.50
5.4.440.0770.05319.41
5.4.430.0630.06019.57
5.4.420.0100.05319.19
5.4.410.0600.06019.06
5.4.400.0570.06019.13
5.4.390.0570.06018.87
5.4.380.0670.04318.86
5.4.370.0730.05018.98
5.4.360.0770.04719.06
5.4.350.0730.05719.24
5.4.340.0060.03712.04
5.4.320.0070.04112.53
5.4.310.0060.03712.53
5.4.300.0060.04312.52
5.4.290.0060.03912.53
5.4.280.0050.03512.43
5.4.270.0060.03512.43
5.4.260.0040.03812.42
5.4.250.0070.04412.42
5.4.240.0080.03912.42
5.4.230.0050.03812.41
5.4.220.0050.03512.41
5.4.210.0100.03812.41
5.4.200.0060.04012.41
5.4.190.0050.04212.41
5.4.180.0040.04512.41
5.4.170.0050.03712.42
5.4.160.0040.03712.42
5.4.150.0050.03712.41
5.4.140.0080.03512.10
5.4.130.0060.04112.09
5.4.120.0040.03712.05
5.4.110.0040.04512.04
5.4.100.0050.03912.04
5.4.90.0070.04112.04
5.4.80.0080.03812.04
5.4.70.0070.03712.04
5.4.60.0050.03812.04
5.4.50.0050.03512.04
5.4.40.0060.03312.02
5.4.30.0040.03812.02
5.4.20.0030.03612.02
5.4.10.0070.03312.02
5.4.00.0040.04011.51
5.3.290.0060.03912.80
5.3.280.0060.04012.71
5.3.270.0070.03912.72
5.3.260.0050.04012.72
5.3.250.0040.03812.71
5.3.240.0070.03712.72
5.3.230.0100.04312.71
5.3.220.0070.03612.68
5.3.210.0110.03812.68
5.3.200.0010.04112.68
5.3.190.0100.03812.67
5.3.180.0070.03612.67
5.3.170.0040.03812.67
5.3.160.0100.04012.68
5.3.150.0040.04012.68
5.3.140.0070.03612.66
5.3.130.0090.03612.66
5.3.120.0060.03912.66
5.3.110.0060.03712.66
5.3.100.0030.03912.13
5.3.90.0080.03412.11
5.3.80.0040.03812.09
5.3.70.0050.04112.09
5.3.60.0070.04012.08
5.3.50.0050.03712.02
5.3.40.0090.03912.02
5.3.30.0050.04011.98
5.3.20.0060.03411.77
5.3.10.0060.03411.74
5.3.00.0070.03311.72
5.2.170.0060.0289.22
5.2.160.0090.0299.22
5.2.150.0030.0339.22
5.2.140.0050.0359.21
5.2.130.0050.0309.18
5.2.120.0060.0279.18
5.2.110.0050.0429.18
5.2.100.0040.0299.18
5.2.90.0060.0279.18
5.2.80.0030.0319.17
5.2.70.0040.0319.18
5.2.60.0060.0299.13
5.2.50.0070.0369.09
5.2.40.0060.0329.07
5.2.30.0090.0299.05
5.2.20.0050.0279.04
5.2.10.0030.0298.95
5.2.00.0090.0328.81
5.1.60.0050.0328.09
5.1.50.0090.0338.09
5.1.40.0070.0238.06
5.1.30.0020.0308.42
5.1.20.0050.0268.44
5.1.10.0070.0238.16
5.1.00.0040.0258.16
5.0.50.0050.0196.64
5.0.40.0040.0196.50
5.0.30.0050.0296.31
5.0.20.0070.0156.29
5.0.10.0030.0196.26
5.0.00.0020.0326.25
4.4.90.0050.0164.78
4.4.80.0020.0184.76
4.4.70.0020.0184.76
4.4.60.0030.0194.76
4.4.50.0040.0164.77
4.4.40.0060.0244.71
4.4.30.0040.0154.76
4.4.20.0040.0184.85
4.4.10.0020.0194.85
4.4.00.0030.0304.76
4.3.110.0050.0144.67
4.3.100.0030.0224.66
4.3.90.0050.0144.64
4.3.80.0050.0214.59
4.3.70.0080.0214.63
4.3.60.0040.0144.63
4.3.50.0050.0174.63
4.3.40.0020.0254.54
4.3.30.0060.0283.30
4.3.20.0010.0243.27
4.3.10.0010.0173.24
4.3.00.0100.0207.11

preferences:
46.7 ms | 401 KiB | 5 Q