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]));

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.30
8.3.50.0150.00521.14
8.3.40.0090.00618.70
8.3.30.0070.00719.22
8.3.20.0000.00820.24
8.3.10.0080.00023.67
8.3.00.0080.00019.25
8.2.180.0120.00416.50
8.2.170.0070.00722.96
8.2.160.0130.00318.79
8.2.150.0040.01224.18
8.2.140.0080.00824.66
8.2.130.0050.00226.16
8.2.120.0080.00020.97
8.2.110.0030.00622.25
8.2.100.0040.00718.22
8.2.90.0050.00319.20
8.2.80.0050.00317.97
8.2.70.0030.00617.63
8.2.60.0030.00917.93
8.2.50.0040.00418.07
8.2.40.0040.00419.94
8.2.30.0080.00018.05
8.2.20.0060.00317.84
8.2.10.0040.00418.07
8.2.00.0070.00017.68
8.1.280.0060.01025.92
8.1.270.0040.00422.13
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0090.00022.81
8.1.230.0120.00317.66
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.25
8.1.190.0000.00817.23
8.1.180.0050.00318.10
8.1.170.0030.00618.62
8.1.160.0030.00322.00
8.1.150.0040.00418.93
8.1.140.0040.00417.50
8.1.130.0030.00317.84
8.1.120.0070.00017.54
8.1.110.0040.00417.40
8.1.100.0070.00017.54
8.1.90.0000.00717.48
8.1.80.0000.00717.52
8.1.70.0000.00717.42
8.1.60.0060.00317.56
8.1.50.0060.00317.60
8.1.40.0040.00417.43
8.1.30.0050.00317.61
8.1.20.0050.00317.66
8.1.10.0040.00417.51
8.1.00.0000.00817.52
8.0.300.0080.00018.77
8.0.290.0000.00817.00
8.0.280.0040.00418.51
8.0.270.0050.00217.37
8.0.260.0080.00018.40
8.0.250.0070.00017.09
8.0.240.0040.00416.97
8.0.230.0030.00317.06
8.0.220.0030.00316.99
8.0.210.0000.00817.04
8.0.200.0000.00717.07
8.0.190.0030.00517.07
8.0.180.0040.00417.04
8.0.170.0000.00816.94
8.0.160.0040.00416.92
8.0.150.0000.00716.79
8.0.140.0040.00416.93
8.0.130.0000.00613.51
8.0.120.0000.00817.04
8.0.110.0040.00416.92
8.0.100.0040.00417.01
8.0.90.0040.00416.92
8.0.80.0030.01617.01
8.0.70.0040.00416.93
8.0.60.0030.00517.00
8.0.50.0050.00316.91
8.0.30.0100.01117.11
8.0.20.0170.00617.40
8.0.10.0030.00617.02
8.0.00.0140.00416.78
7.4.330.0050.00015.02
7.4.320.0030.00516.64
7.4.300.0030.00316.51
7.4.290.0050.00316.46
7.4.280.0080.00016.54
7.4.270.0050.00316.67
7.4.260.0030.00316.54
7.4.250.0070.00016.55
7.4.240.0020.00616.70
7.4.230.0030.00316.75
7.4.220.0160.00316.60
7.4.210.0060.00916.59
7.4.200.0040.00416.59
7.4.160.0060.00916.63
7.4.150.0180.00617.40
7.4.140.0090.01117.86
7.4.130.0080.00816.52
7.4.120.0080.00816.54
7.4.110.0090.00916.67
7.4.100.0120.00416.53
7.4.90.0140.00716.54
7.4.80.0110.01219.39
7.4.70.0060.01016.50
7.4.60.0110.00616.59
7.4.50.0000.00416.41
7.4.40.0000.01716.57
7.4.30.0090.01216.58
7.4.00.0040.01414.99
7.3.330.0030.00313.33
7.3.320.0050.00013.43
7.3.310.0030.00316.27
7.3.300.0000.00716.50
7.3.290.0090.00716.42
7.3.280.0070.01216.38
7.3.270.0040.01717.40
7.3.260.0130.00516.63
7.3.250.0120.00516.36
7.3.240.0040.01416.53
7.3.230.0070.01016.64
7.3.210.0070.01716.45
7.3.200.0130.00719.39
7.3.190.0130.00516.26
7.3.180.0060.00916.70
7.3.170.0100.00716.52
7.3.160.0110.00416.40
7.3.120.0130.00314.62
7.3.110.0070.01014.79
7.3.100.0040.00814.78
7.3.90.0110.00314.98
7.3.80.0060.00914.63
7.3.70.0030.01014.79
7.3.60.0030.01314.80
7.3.50.0000.01115.05
7.3.40.0090.00614.63
7.3.30.0090.00614.84
7.3.20.0060.00616.79
7.3.10.0040.01116.61
7.3.00.0030.00816.50
7.2.330.0170.00016.46
7.2.320.0090.00916.75
7.2.310.0060.01216.73
7.2.300.0100.01016.62
7.2.290.0080.01316.66
7.2.250.0030.01715.09
7.2.240.0000.02015.05
7.2.230.0030.00615.13
7.2.220.0000.01515.31
7.2.210.0070.00715.11
7.2.200.0090.00915.19
7.2.190.0000.01815.29
7.2.180.0030.00915.11
7.2.170.0000.01315.05
7.2.130.0090.00916.91
7.2.120.0040.01416.77
7.2.110.0000.01116.60
7.2.100.0030.00916.59
7.2.90.0000.01416.96
7.2.80.0060.00916.94
7.2.70.0070.00716.87
7.2.60.0040.01117.03
7.2.50.0140.00017.04
7.2.40.0040.00816.83
7.2.30.0080.00417.03
7.2.20.0070.00416.93
7.2.10.0000.00917.04
7.2.00.0030.01018.19
7.1.330.0100.00315.86
7.1.320.0030.01216.01
7.1.310.0060.00915.55
7.1.300.0080.00415.96
7.1.290.0090.00615.84
7.1.280.0090.00615.84
7.1.270.0030.01015.81
7.1.260.0080.00815.71
7.1.250.0000.01215.59
7.1.100.0040.01118.21
7.1.70.0080.00017.20
7.1.60.0100.01319.11
7.1.50.0100.01417.01
7.1.00.0030.07722.41
7.0.200.0000.01616.92
7.0.140.0030.07721.93
7.0.60.0230.06319.95
7.0.50.0070.08717.90
7.0.40.0030.06719.96
7.0.30.0270.06320.06
7.0.20.0200.04320.26
7.0.10.0000.04720.07
7.0.00.0070.04020.32
5.6.280.0070.07320.79
5.6.210.0130.05020.57
5.6.200.0070.08018.20
5.6.190.0030.09020.58
5.6.180.0370.07020.58
5.6.170.0330.07320.62
5.6.160.0170.07320.46
5.6.150.0000.04318.16
5.6.140.0100.07018.20
5.6.130.0070.08318.16
5.6.120.0170.08021.04
5.6.110.0100.08021.01
5.6.100.0070.07321.13
5.6.90.0030.09320.97
5.6.80.0030.05720.46
5.5.350.0000.08720.46
5.5.340.0100.03318.02
5.5.330.0070.05720.57
5.5.320.0400.06720.38
5.5.310.0370.07020.27
5.5.300.0000.04318.02
5.5.290.0030.08318.05
5.5.280.0030.05320.99
5.5.270.0130.07320.82
5.5.260.0070.04320.70
5.5.250.0070.08320.74
5.5.240.0230.05320.09
5.4.450.0830.05319.32
5.4.440.1000.08719.36
5.4.430.0700.05319.55
5.4.420.1030.05019.36
5.4.410.0770.06719.35
5.4.400.1030.05019.30
5.4.390.0700.06318.98
5.4.380.0100.05319.29
5.4.370.0770.05018.88
5.4.360.0070.07019.17
5.4.350.0770.05319.29
5.4.340.0110.02912.04
5.4.320.0070.03512.53
5.4.310.0070.03912.53
5.4.300.0080.03512.54
5.4.290.0070.03712.53
5.4.280.0060.03712.42
5.4.270.0070.03512.43
5.4.260.0040.04012.42
5.4.250.0070.03612.43
5.4.240.0080.03612.42
5.4.230.0090.03512.42
5.4.220.0040.03912.42
5.4.210.0080.03812.42
5.4.200.0100.04512.41
5.4.190.0090.04112.41
5.4.180.0070.03612.41
5.4.170.0070.03712.43
5.4.160.0070.03712.43
5.4.150.0040.03812.42
5.4.140.0070.04512.10
5.4.130.0050.03712.09
5.4.120.0070.03712.05
5.4.110.0070.03712.04
5.4.100.0070.03612.04
5.4.90.0050.04112.04
5.4.80.0070.04812.05
5.4.70.0110.03812.04
5.4.60.0110.03112.04
5.4.50.0090.03412.04
5.4.40.0090.03612.03
5.4.30.0070.04012.02
5.4.20.0140.03612.02
5.4.10.0120.04312.03
5.4.00.0080.03411.52
5.3.290.0080.04212.80
5.3.280.0100.04012.71
5.3.270.0080.03712.73
5.3.260.0030.04112.72
5.3.250.0050.03812.72
5.3.240.0060.03812.72
5.3.230.0050.04012.71
5.3.220.0060.04012.68
5.3.210.0080.05112.68
5.3.200.0060.03712.68
5.3.190.0070.03612.68
5.3.180.0020.03912.67
5.3.170.0030.04212.67
5.3.160.0090.03912.68
5.3.150.0060.04112.67
5.3.140.0090.03312.66
5.3.130.0040.04412.65
5.3.120.0040.04512.66
5.3.110.0070.04412.66
5.3.100.0070.03612.13
5.3.90.0080.03912.11
5.3.80.0030.03912.09
5.3.70.0050.03712.09
5.3.60.0070.03612.08
5.3.50.0090.03312.02
5.3.40.0060.03612.02
5.3.30.0100.03111.98
5.3.20.0090.03211.76
5.3.10.0060.03511.73
5.3.00.0070.03511.71
5.2.170.0050.0339.22
5.2.160.0040.0349.22
5.2.150.0040.0349.22
5.2.140.0020.0339.21
5.2.130.0040.0299.18
5.2.120.0080.0259.18
5.2.110.0020.0329.18
5.2.100.0050.0509.18
5.2.90.0040.0349.18
5.2.80.0070.0299.17
5.2.70.0110.0359.17
5.2.60.0050.0419.13
5.2.50.0030.0439.09
5.2.40.0090.0329.07
5.2.30.0030.0329.05
5.2.20.0080.0429.04
5.2.10.0060.0438.95
5.2.00.0050.0418.81
5.1.60.0050.0248.09
5.1.50.0020.0278.09
5.1.40.0040.0298.07
5.1.30.0050.0338.42
5.1.20.0040.0268.44
5.1.10.0070.0238.16
5.1.00.0050.0258.16
5.0.50.0030.0216.64
5.0.40.0030.0216.51
5.0.30.0000.0366.31
5.0.20.0040.0206.29
5.0.10.0010.0236.26
5.0.00.0060.0326.25
4.4.90.0040.0184.78
4.4.80.0020.0164.75
4.4.70.0030.0164.75
4.4.60.0030.0154.76
4.4.50.0020.0174.77
4.4.40.0020.0274.71
4.4.30.0030.0174.76
4.4.20.0020.0224.84
4.4.10.0050.0204.85
4.4.00.0040.0254.76
4.3.110.0010.0174.67
4.3.100.0030.0154.67
4.3.90.0020.0154.63
4.3.80.0050.0234.59
4.3.70.0040.0144.63
4.3.60.0010.0174.62
4.3.50.0040.0204.63
4.3.40.0070.0274.54
4.3.30.0050.0523.30
4.3.20.0020.0213.28
4.3.10.0020.0213.24
4.3.00.0200.0206.68

preferences:
57.13 ms | 401 KiB | 5 Q