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, 1, 2, 1]) === [[1, 1], [2], [1]]); print_r(array_group(function ($a, $b) { return $a <= ($b-1); }, [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.55
8.3.50.0140.00621.27
8.3.40.0120.00318.66
8.3.30.0070.00719.08
8.3.20.0080.00020.29
8.3.10.0040.00423.59
8.3.00.0040.00419.24
8.2.180.0070.00718.41
8.2.170.0110.00422.96
8.2.160.0160.00320.57
8.2.150.0080.00824.18
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0140.00022.13
8.2.110.0030.00622.08
8.2.100.0030.00917.63
8.2.90.0040.00419.36
8.2.80.0060.00317.97
8.2.70.0000.00817.50
8.2.60.0030.00717.93
8.2.50.0080.00018.07
8.2.40.0030.00518.28
8.2.30.0050.00218.17
8.2.20.0000.00817.74
8.2.10.0080.00018.04
8.2.00.0040.00417.78
8.1.280.0140.00025.92
8.1.270.0050.00322.19
8.1.260.0070.00026.35
8.1.250.0000.00828.09
8.1.240.0050.00524.02
8.1.230.0070.00418.98
8.1.220.0050.00317.74
8.1.210.0060.00318.77
8.1.200.0030.00617.22
8.1.190.0040.00417.12
8.1.180.0080.00018.10
8.1.170.0040.00418.44
8.1.160.0040.00422.07
8.1.150.0000.00718.81
8.1.140.0050.00217.51
8.1.130.0030.00317.82
8.1.120.0040.00417.48
8.1.110.0040.00417.52
8.1.100.0040.00417.48
8.1.90.0000.00717.40
8.1.80.0000.00717.51
8.1.70.0000.00717.46
8.1.60.0070.00317.68
8.1.50.0080.00017.57
8.1.40.0000.00717.55
8.1.30.0040.00417.61
8.1.20.0000.00817.61
8.1.10.0040.00417.63
8.1.00.0000.00817.54
8.0.300.0040.00418.77
8.0.290.0040.00417.00
8.0.280.0000.00718.55
8.0.270.0030.00317.32
8.0.260.0000.00617.32
8.0.250.0000.00716.96
8.0.240.0000.00717.03
8.0.230.0030.00317.11
8.0.220.0030.00316.97
8.0.210.0070.00017.02
8.0.200.0040.00417.10
8.0.190.0040.00417.07
8.0.180.0030.00317.09
8.0.170.0070.00017.09
8.0.160.0000.00717.04
8.0.150.0000.00717.02
8.0.140.0060.00316.89
8.0.130.0030.00313.43
8.0.120.0050.00317.00
8.0.110.0000.00816.99
8.0.100.0000.00817.01
8.0.90.0000.00717.14
8.0.80.0130.00717.07
8.0.70.0000.00716.84
8.0.60.0070.00016.98
8.0.50.0050.00316.89
8.0.30.0100.01317.22
8.0.20.0070.01217.40
8.0.10.0040.00417.11
8.0.00.0110.00616.95
7.4.330.0000.00515.02
7.4.320.0030.00616.55
7.4.300.0000.00616.55
7.4.290.0030.00316.58
7.4.280.0000.00716.48
7.4.270.0080.00016.46
7.4.260.0040.00416.68
7.4.250.0030.00516.51
7.4.240.0040.00316.64
7.4.230.0000.00716.47
7.4.220.0060.01316.76
7.4.210.0090.00916.70
7.4.200.0000.00816.77
7.4.160.0110.00616.68
7.4.150.0120.00817.40
7.4.140.0110.00817.86
7.4.130.0070.01016.53
7.4.120.0120.00516.56
7.4.110.0030.01416.60
7.4.100.0070.01016.55
7.4.90.0180.00416.64
7.4.80.0140.00419.39
7.4.70.0120.00416.65
7.4.60.0090.00916.47
7.4.50.0030.00316.49
7.4.40.0060.01116.75
7.4.30.0070.01316.48
7.4.00.0070.01015.01
7.3.330.0050.00013.40
7.3.320.0030.00313.39
7.3.310.0050.00216.44
7.3.300.0000.00716.34
7.3.290.0080.00716.38
7.3.280.0100.00816.41
7.3.270.0040.01317.40
7.3.260.0090.01516.43
7.3.250.0110.00916.50
7.3.240.0090.00816.39
7.3.230.0070.01016.39
7.3.210.0050.01316.52
7.3.200.0040.01219.39
7.3.190.0070.01016.59
7.3.180.0160.00616.39
7.3.170.0100.01316.53
7.3.160.0090.00616.63
7.2.330.0130.00416.55
7.2.320.0130.01016.73
7.2.310.0070.01016.78
7.2.300.0040.01816.47
7.2.290.0060.01616.61
7.2.60.0070.00716.57
7.2.00.0130.00719.39
7.1.200.0050.00515.64
7.1.100.0100.00318.09
7.1.70.0000.00717.36
7.1.60.0100.01319.11
7.1.50.0070.01417.02
7.1.00.0000.08022.43
7.0.200.0030.01216.58
7.0.140.0030.07322.00
7.0.110.0170.07019.90
7.0.100.0030.07320.16
7.0.90.0100.08020.05
7.0.80.0170.07719.98
7.0.70.0070.08320.04
7.0.60.0170.05320.03
7.0.50.0070.04319.96
7.0.40.0070.07719.78
7.0.30.0070.04719.79
7.0.20.0070.07719.78
7.0.10.0070.06319.73
7.0.00.0100.08719.73
5.6.280.0070.07020.81
5.6.260.0000.08020.68
5.6.250.0130.07320.63
5.6.240.0100.08020.60
5.6.230.0200.07020.57
5.6.220.0070.07720.59
5.6.210.0030.05020.62
5.6.200.0030.09020.66
5.6.190.0100.08020.62
5.6.180.0070.07720.73
5.6.170.0100.07720.69
5.6.160.0130.07320.59
5.6.150.0070.08320.67
5.6.140.0030.09020.71
5.6.130.0100.07720.58
5.6.120.0070.08720.59
5.6.110.0100.08320.57
5.6.100.0030.07720.65
5.6.90.0200.06320.63
5.6.80.0130.07320.07
5.6.70.0130.07320.05
5.6.60.0170.07019.95
5.6.50.0000.06320.02
5.6.40.0130.07320.10
5.6.30.0130.07320.09
5.6.20.0070.08320.04
5.6.10.0030.08319.95
5.6.00.0100.08019.88
5.5.380.0130.04017.63
5.5.370.0130.07017.57
5.5.360.0130.07317.71
5.5.350.0130.07317.29
5.5.340.0100.07318.11
5.5.330.0100.06717.93
5.5.320.0100.07018.23
5.5.310.0100.07017.95
5.5.300.0070.07718.11
5.5.290.0070.08017.92
5.5.280.0100.05317.98
5.5.270.0030.06717.88
5.5.260.0100.08017.84
5.5.250.0130.06718.04
5.5.240.0070.07717.33
5.5.230.0100.08017.51
5.5.220.0030.07717.43
5.5.210.0100.07717.61
5.5.200.0170.06717.20
5.5.190.0070.07717.32
5.5.180.0170.06717.43
5.5.160.0100.07317.30
5.5.150.0100.04017.48
5.5.140.0030.07717.27
5.5.130.0030.07717.26
5.5.120.0070.04317.28
5.5.110.0030.07717.27
5.5.100.0170.06717.48
5.5.90.0030.08017.48
5.5.80.0130.07017.09
5.5.70.0100.07317.34
5.5.60.0030.05017.34
5.5.50.0100.07317.34
5.5.40.0030.06717.34
5.5.30.0130.06717.34
5.5.20.0130.07717.29
5.5.10.0070.06317.17
5.5.00.0100.07017.46
5.4.450.0070.08319.50
5.4.440.0100.06719.27
5.4.430.0070.06319.34
5.4.420.0100.07719.51
5.4.410.0130.07019.21
5.4.400.0000.07719.00
5.4.390.0070.07319.18
5.4.380.0030.07319.17
5.4.370.0200.06719.00
5.4.360.0170.07019.02
5.4.350.0030.07718.99
5.4.340.0100.07719.19
5.4.320.0070.07719.23
5.4.310.0030.07019.01
5.4.300.0070.07719.00
5.4.290.0100.07319.17
5.4.280.0100.07019.14
5.4.270.0100.08018.98
5.4.260.0070.07719.34
5.4.250.0100.05019.02
5.4.240.0070.07319.17
5.4.230.0130.07019.18
5.4.220.0070.05318.99
5.4.210.0170.07019.33
5.4.200.0070.07319.11
5.4.190.0100.07019.25
5.4.180.0170.04019.24
5.4.170.0100.07719.15
5.4.160.0070.08019.16
5.4.150.0070.07019.14
5.4.140.0200.06016.45
5.4.130.0070.07316.61
5.4.120.0070.07016.38
5.4.110.0100.06716.46
5.4.100.0030.07316.67
5.4.90.0100.06716.48
5.4.80.0070.07316.51
5.4.70.0070.06016.45
5.4.60.0070.07316.48
5.4.50.0170.06716.64
5.4.40.0100.07716.45
5.4.30.0030.06016.30
5.4.20.0070.07316.41
5.4.10.0100.03716.43
5.4.00.0100.07016.00
5.3.290.0100.07014.66
5.3.280.0100.07314.74
5.3.270.0100.04314.70
5.3.260.0100.06714.64
5.3.250.0070.08014.74
5.3.240.0000.07014.75
5.3.230.0100.03714.64
5.3.220.0130.07014.64
5.3.210.0130.06314.64
5.3.200.0070.07014.64
5.3.190.0070.07314.71
5.3.180.0070.05714.66
5.3.170.0030.08314.64
5.3.160.0030.07314.64
5.3.150.0170.06014.79
5.3.140.0030.07714.79
5.3.130.0130.07014.64
5.3.120.0070.07714.64
5.3.110.0000.08014.64
5.3.100.0130.06014.64
5.3.90.0130.06714.64
5.3.80.0130.06714.64
5.3.70.0000.05014.64
5.3.60.0070.05714.64
5.3.50.0130.07014.64
5.3.40.0130.06714.64
5.3.30.0070.06314.64
5.3.20.0170.06314.64
5.3.10.0030.07014.64
5.3.00.0130.06714.64
5.2.170.0070.06014.64
5.2.160.0070.05714.64
5.2.150.0070.04714.64
5.2.140.0070.07714.64
5.2.130.0000.03314.64
5.2.120.0070.03714.64
5.2.110.0030.07014.64
5.2.100.0130.05314.64
5.2.90.0070.06014.64
5.2.80.0070.06314.64
5.2.70.0030.03314.64
5.2.60.0030.03714.64
5.2.50.0070.06014.64
5.2.40.0030.06714.64
5.2.30.0030.06714.64
5.2.20.0100.02714.64
5.2.10.0030.04314.64
5.2.00.0070.05714.64
5.1.60.0000.05714.64
5.1.50.0000.05014.64
5.1.40.0070.03014.64
5.1.30.0000.06014.64
5.1.20.0030.06014.64
5.1.10.0100.04014.64
5.1.00.0170.04314.64
5.0.50.0100.04014.64
5.0.40.0100.04014.64
5.0.30.0000.06714.64
5.0.20.0070.02014.64
5.0.10.0070.04314.64
5.0.00.0100.03714.64
4.4.90.0000.03714.64
4.4.80.0000.03714.64
4.4.70.0030.03314.64
4.4.60.0030.03314.64
4.4.50.0000.03714.64
4.4.40.0030.02714.64
4.4.30.0000.03714.64
4.4.20.0000.03014.64
4.4.10.0030.03314.64
4.4.00.0000.05714.64
4.3.110.0070.01714.64
4.3.100.0030.02014.64
4.3.90.0030.03314.64
4.3.80.0000.05714.64
4.3.70.0000.03714.64
4.3.60.0070.03014.64
4.3.50.0000.03714.64
4.3.40.0070.04714.64
4.3.30.0030.03314.64
4.3.20.0030.02314.64
4.3.10.0070.03314.64
4.3.00.0000.03314.64

preferences:
38.8 ms | 401 KiB | 5 Q