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(callable $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, 2, 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.01018.52
8.3.50.0110.00716.39
8.3.40.0090.00618.92
8.3.30.0100.00319.04
8.3.20.0080.00020.39
8.3.10.0050.00323.65
8.3.00.0030.00519.38
8.2.180.0120.00618.41
8.2.170.0140.00022.96
8.2.160.0070.00720.32
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0050.00226.16
8.2.120.0000.00722.08
8.2.110.0030.00620.47
8.2.100.0090.00317.91
8.2.90.0060.00319.25
8.2.80.0030.00517.97
8.2.70.0060.00317.73
8.2.60.0040.00418.03
8.2.50.0030.00618.07
8.2.40.0030.00620.00
8.2.30.0000.00718.17
8.2.20.0040.00417.70
8.2.10.0020.00518.04
8.2.00.0000.00817.71
8.1.280.0110.01125.92
8.1.270.0000.00822.19
8.1.260.0080.00026.35
8.1.250.0050.00228.09
8.1.240.0090.00023.83
8.1.230.0050.00520.85
8.1.220.0040.00417.74
8.1.210.0030.00518.77
8.1.200.0060.00317.10
8.1.190.0030.00617.23
8.1.180.0030.00618.10
8.1.170.0040.00418.65
8.1.160.0040.00421.98
8.1.150.0000.00718.84
8.1.140.0000.00917.59
8.1.130.0040.00417.88
8.1.120.0000.00717.41
8.1.110.0040.00417.45
8.1.100.0040.00417.50
8.1.90.0040.00417.50
8.1.80.0020.00517.46
8.1.70.0000.00817.43
8.1.60.0030.00617.68
8.1.50.0040.00417.61
8.1.40.0080.00017.58
8.1.30.0040.00417.53
8.1.20.0000.00817.69
8.1.10.0000.00817.49
8.1.00.0040.00417.63
8.0.300.0040.00419.89
8.0.290.0000.00716.61
8.0.280.0030.00318.49
8.0.270.0060.00317.36
8.0.260.0000.00617.22
8.0.250.0000.00717.11
8.0.240.0050.00217.07
8.0.230.0000.00716.98
8.0.220.0050.00517.00
8.0.210.0030.00317.00
8.0.200.0030.00316.91
8.0.190.0000.01017.04
8.0.180.0080.00017.02
8.0.170.0030.00517.05
8.0.160.0030.00317.02
8.0.150.0040.00417.01
8.0.140.0040.00316.98
8.0.130.0000.00613.40
8.0.120.0000.00816.98
8.0.110.0000.00816.98
8.0.100.0040.00417.04
8.0.90.0040.00417.03
8.0.80.0110.01016.99
8.0.70.0040.00417.01
8.0.60.0050.00217.04
8.0.50.0050.00316.89
8.0.30.0140.01117.07
8.0.20.0160.00917.40
8.0.10.0040.00417.14
8.0.00.0040.01216.92
7.4.330.0000.00515.00
7.4.320.0000.00616.67
7.4.300.0000.00616.48
7.4.290.0070.00016.57
7.4.280.0000.01016.66
7.4.270.0030.00316.57
7.4.260.0000.00716.45
7.4.250.0030.00516.61
7.4.240.0000.00716.58
7.4.230.0070.00016.45
7.4.220.0070.01116.77
7.4.210.0030.01016.62
7.4.200.0000.00716.46
7.4.160.0100.00616.60
7.4.150.0050.01417.40
7.4.140.0110.00717.86
7.4.130.0100.00816.63
7.4.120.0110.00616.64
7.4.110.0030.01416.71
7.4.100.0120.00616.61
7.4.90.0090.01016.73
7.4.80.0170.00419.39
7.4.70.0100.00616.61
7.4.60.0070.01416.47
7.4.50.0030.00616.64
7.4.40.0030.01416.52
7.4.30.0120.00616.68
7.4.00.0080.00814.97
7.3.330.0000.00513.27
7.3.320.0000.00613.25
7.3.310.0070.00016.27
7.3.300.0000.00816.28
7.3.290.0090.00616.42
7.3.280.0110.00716.38
7.3.270.0090.00917.40
7.3.260.0130.01016.56
7.3.250.0090.01016.65
7.3.240.0110.01116.62
7.3.230.0120.00616.62
7.3.210.0060.01116.58
7.3.200.0060.01019.39
7.3.190.0110.01116.57
7.3.180.0130.00316.54
7.3.170.0110.00516.69
7.3.160.0090.00616.52
7.3.10.0070.00316.44
7.3.00.0030.00716.32
7.2.330.0070.01016.69
7.2.320.0030.01416.61
7.2.310.0100.00716.71
7.2.300.0130.01016.85
7.2.290.0130.00316.58
7.2.130.0000.01417.10
7.2.120.0060.00616.82
7.2.110.0060.00616.89
7.2.100.0080.00816.93
7.2.90.0040.00816.80
7.2.80.0070.00616.79
7.2.70.0070.00717.09
7.2.60.0140.01116.92
7.2.50.0070.01016.97
7.2.40.0060.00616.97
7.2.30.0040.00817.00
7.2.20.0030.00817.07
7.2.10.0000.01216.98
7.2.00.0050.00518.06
7.1.250.0030.00715.59
7.1.200.0040.00815.97
7.1.100.0040.00718.20
7.1.70.0030.00916.91
7.1.60.0070.01419.11
7.1.50.0030.02016.99
7.1.00.0030.07722.54
7.0.200.0030.00616.79
7.0.140.0030.07322.23
7.0.100.0070.08320.04
7.0.90.0200.06719.92
7.0.80.0230.06020.02
7.0.70.0170.05019.96
7.0.60.0130.07019.99
7.0.50.0070.08720.19
7.0.40.0100.07720.09
7.0.30.0130.08020.03
7.0.20.0100.04020.05
7.0.10.0030.04720.03
7.0.00.0100.06320.14
5.6.250.0030.08320.65
5.6.240.0130.06320.60
5.6.230.0130.07320.50
5.6.220.0070.08320.67
5.6.210.0000.05720.66
5.6.200.0130.07321.11
5.6.190.0070.07021.06
5.6.180.0100.08021.03
5.6.170.0130.08020.99
5.6.160.0100.06021.14
5.6.150.0230.07021.04
5.6.140.0130.06720.93
5.6.130.0230.06720.93
5.6.120.0070.05021.13
5.6.110.0100.08321.08
5.6.100.0070.05021.09
5.6.90.0230.07320.98
5.6.80.0100.08020.58
5.6.70.0070.04320.34
5.6.60.0000.09020.41
5.6.50.0100.03720.35
5.6.40.0130.06720.39
5.6.30.0130.07020.42
5.6.20.0070.04720.45
5.6.10.0070.06720.41
5.6.00.0070.04020.47
5.5.380.0130.07020.37
5.5.370.0070.09020.48
5.5.360.0070.08320.47
5.5.350.0130.06720.45
5.5.340.0100.05320.82
5.5.330.0030.04720.90
5.5.320.0170.07320.93
5.5.310.0070.08020.85
5.5.300.0100.05320.79
5.5.290.0030.08320.95
5.5.280.0030.08720.93
5.5.270.0070.07720.88
5.5.260.0030.09020.93
5.5.250.0070.07020.73
5.5.240.0070.08020.15
5.5.230.0070.06720.28
5.5.220.0100.07320.26
5.5.210.0170.07720.18
5.5.200.0100.07720.17
5.5.190.0030.08020.23
5.5.180.0170.07020.27
5.5.160.0100.08020.26
5.5.150.0130.06720.30
5.5.140.0070.07720.25
5.5.130.0070.05020.28
5.5.120.0170.03720.26
5.5.110.0070.04720.24
5.5.100.0100.04320.18
5.5.90.0000.04320.09
5.5.80.0030.04720.11
5.5.70.0070.03320.07
5.5.60.0130.03020.02
5.5.50.0000.04020.16
5.5.40.0000.04720.17
5.5.30.0030.04020.05
5.5.20.0000.03719.98
5.5.10.0070.03720.06
5.5.00.0000.04320.00
5.4.450.0170.06319.23
5.4.440.0130.04319.37
5.4.430.0070.04319.35
5.4.420.0100.07319.44
5.4.410.0130.06719.12
5.4.400.0030.07719.13
5.4.390.0100.07019.05
5.4.380.0130.03719.16
5.4.370.0100.05319.15
5.4.360.0030.05019.18
5.4.350.0030.07018.87
5.4.340.0000.05018.95
5.4.320.0030.04719.15
5.4.310.0070.07019.03
5.4.300.0030.06018.86
5.4.290.0100.07318.89
5.4.280.0070.04319.02
5.4.270.0130.07318.87
5.4.260.0030.07319.12
5.4.250.0070.06718.89
5.4.240.0130.03719.03
5.4.230.0000.04318.94
5.4.220.0030.04018.87
5.4.210.0070.03319.04
5.4.200.0000.04019.08
5.4.190.0000.04018.91
5.4.180.0030.03718.84
5.4.170.0000.04019.15
5.4.160.0000.04019.14
5.4.150.0130.02719.19
5.4.140.0000.04716.44
5.4.130.0130.02016.44
5.4.120.0070.03316.41
5.4.110.0030.03716.56
5.4.100.0000.04016.52
5.4.90.0030.03016.38
5.4.80.0100.02316.50
5.4.70.0000.03716.55
5.4.60.0030.03316.50
5.4.50.0170.02716.45
5.4.40.0100.03016.50
5.4.30.0070.03316.49
5.4.20.0070.03016.45
5.4.10.0070.02716.48
5.4.00.0000.03715.83
5.3.290.0030.07314.66
5.3.280.0100.03314.73
5.3.270.0000.03314.57
5.3.260.0030.03714.55
5.3.250.0000.03314.56
5.3.240.0070.04714.72
5.3.230.0100.06314.69
5.3.220.0000.04014.52
5.3.210.0100.03314.56
5.3.200.0000.04314.60
5.3.190.0000.06714.57
5.3.180.0030.03714.56
5.3.170.0070.03714.57
5.3.160.0030.03714.60
5.3.150.0130.02714.55
5.3.140.0070.03314.61
5.3.130.0000.03714.53
5.3.120.0000.04014.69
5.3.110.0070.03314.67
5.3.100.0000.04014.11
5.3.90.0070.02714.09
5.3.80.0030.06014.07
5.3.70.0130.03014.00
5.3.60.0070.02714.06
5.3.50.0070.03013.86
5.3.40.0100.03014.03
5.3.30.0100.03313.90
5.3.20.0030.03313.68
5.3.10.0000.03313.78
5.3.00.0030.04013.70
5.2.170.0030.02311.57
5.2.160.0000.03011.57
5.2.150.0000.03311.57
5.2.140.0000.03711.57
5.2.130.0000.02711.57
5.2.120.0000.03011.57
5.2.110.0030.02711.57
5.2.100.0000.02711.57
5.2.90.0070.02311.57
5.2.80.0030.02311.57
5.2.70.0030.03311.57
5.2.60.0030.02711.57
5.2.50.0000.02711.57
5.2.40.0070.02311.57
5.2.30.0030.03311.57
5.2.20.0130.02011.57
5.2.10.0070.05711.57
5.2.00.0000.06711.57
5.1.60.0030.04011.57
5.1.50.0000.03711.57
5.1.40.0030.03711.57
5.1.30.0070.05311.57
5.1.20.0030.06011.57
5.1.10.0170.04011.57
5.1.00.0000.05011.57
5.0.50.0070.04711.57
5.0.40.0070.04311.57
5.0.30.0030.03711.57
5.0.20.0030.04011.57
5.0.10.0030.03711.57
5.0.00.0000.05311.57
4.4.90.0000.01711.57
4.4.80.0000.01311.57
4.4.70.0030.02011.57
4.4.60.0000.02011.57
4.4.50.0030.03011.57
4.4.40.0030.05011.57
4.4.30.0000.04011.57
4.4.20.0000.03011.57
4.4.10.0070.03011.57
4.4.00.0030.05011.57
4.3.110.0030.03011.57
4.3.100.0030.02711.57
4.3.90.0000.03711.57
4.3.80.0030.05311.57
4.3.70.0100.02711.57
4.3.60.0000.02711.57
4.3.50.0000.04011.57
4.3.40.0030.05011.57
4.3.30.0070.03311.57
4.3.20.0000.04011.57
4.3.10.0000.03311.57
4.3.00.0000.03711.57

preferences:
42.64 ms | 400 KiB | 5 Q