3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_words($in) { $len = strlen($in); if ($len < 2) { return $in; } // no state $upper = function ($c) { return 'A' <= $c && $c <= 'Z'; }; $lower = function ($c) { return 'a' <= $c && $c <= 'z'; }; $alpha = function ($c) use ($upper, $lower) { return $upper($c) || $lower($c); }; $num = function ($c) { return '0' <= $c && $c <= '9'; }; $alpha_num = function ($c) use ($alpha, $num) { return $alpha($c) || $num($c); }; // stream state $pos = 0; $char = $in[0]; $peek = function() use ($in, &$pos, $len) { if ($pos+1 >= $len) { return null; } return $in[$pos+1]; }; $next = function() use ($peek, &$pos, &$char) { $char = $peek(); $pos++; return $char !== null; }; // lex state $out = array(); $std_word = null; $upr_word = null; $num_word = null; $find_word = function () use (&$char, $alpha_num, $lower, $upper, $next, $peek, &$std_word, &$upr_word, &$num_word) { while (!$alpha_num($char)) { if (!$next()) { return null; } } if ($lower($char)) { return $std_word; // lowercase word } if ($upper($char)) { if ($upper($peek())) { // uppercase word return $upr_word; } return $std_word; // capitalized word } return $num_word; }; $upr_word = function() use (&$out, &$char, $next, $peek, $upper, $lower, $find_word) { $word = $char; while ($next() && $upper($char)) { if ($lower($peek())) { // start of capitalized word (e.g. FOOBar at B) break; } $word .= $char; } $out[] = $word; return $find_word; }; $std_word = function() use (&$out, &$char, $next, $lower, $find_word) { $word = $char; while ($next() && $lower($char)) { $word .= $char; } $out[] = $word; return $find_word; }; $num_word = function() use (&$out, &$char, $next, $num, $find_word) { $word = $char; while ($next() && $num($char)) { $word .= $char; } $out[] = $word; return $find_word; }; $state = $find_word; while ($state !== null) { $state = $state(); } return $out; } $samples = array( 'FooBar123', 'FooBAR123', 'FOOBar123', 'foo_bar_123_Baz', 'FOO_bar_123BAZ', 'FOO_Bar_123baz', 'foo_BAR_123_baz', 'foo_Bar_123_Baz', 'Foo_bar_123_BAZ', ); print_r(array_map(function ($name) { return array( 'name' => $name, 'words' => find_words($name), ); }, $samples));

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.0120.00318.43
8.3.50.0090.00922.05
8.3.40.0180.00318.83
8.3.30.0090.00619.22
8.3.20.0000.00820.28
8.3.10.0060.00321.85
8.3.00.0050.00318.05
8.2.180.0150.00616.63
8.2.170.0070.00722.96
8.2.160.0070.01320.47
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0030.00621.09
8.2.110.0030.00620.77
8.2.100.0130.00018.10
8.2.90.0080.00018.28
8.2.80.0000.00817.97
8.2.70.0040.00417.88
8.2.60.0080.00018.05
8.2.50.0030.00518.07
8.2.40.0000.00918.59
8.2.30.0040.00418.45
8.2.20.0000.00817.92
8.2.10.0000.00718.28
8.2.00.0060.00317.82
8.1.280.0070.01125.92
8.1.270.0040.00423.95
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0060.00322.14
8.1.230.0110.00021.16
8.1.220.0080.00017.80
8.1.210.0050.00318.84
8.1.200.0060.00317.47
8.1.190.0030.00517.25
8.1.180.0000.00818.10
8.1.170.0040.00418.78
8.1.160.0070.00022.04
8.1.150.0040.00418.95
8.1.140.0030.00617.56
8.1.130.0030.00318.00
8.1.120.0000.00717.57
8.1.110.0030.00517.58
8.1.100.0050.00317.60
8.1.90.0000.00717.40
8.1.80.0040.00417.54
8.1.70.0030.00317.56
8.1.60.0030.00617.68
8.1.50.0040.00417.67
8.1.40.0000.00817.54
8.1.30.0000.00817.82
8.1.20.0000.00817.64
8.1.10.0000.00817.60
8.1.00.0050.00317.62
8.0.300.0040.00420.17
8.0.290.0090.00016.88
8.0.280.0030.00318.52
8.0.270.0080.00017.37
8.0.260.0060.00018.62
8.0.250.0030.00317.05
8.0.240.0070.00017.07
8.0.230.0000.00817.15
8.0.220.0030.00317.07
8.0.210.0030.00317.09
8.0.200.0070.00316.97
8.0.190.0000.00817.18
8.0.180.0030.00516.96
8.0.170.0040.00417.00
8.0.160.0030.00517.04
8.0.150.0000.00717.12
8.0.140.0030.00616.95
8.0.130.0030.00313.51
8.0.120.0060.00316.97
8.0.110.0000.00717.12
8.0.100.0030.00517.07
8.0.90.0040.00416.95
8.0.80.0070.01117.04
8.0.70.0000.00716.88
8.0.60.0040.00416.98
8.0.50.0030.00517.09
8.0.30.0060.01317.28
8.0.20.0100.00917.40
8.0.10.0000.00717.07
8.0.00.0130.00616.93
7.4.330.0000.00515.00
7.4.320.0000.00616.61
7.4.300.0000.00616.63
7.4.290.0040.00316.57
7.4.280.0000.00716.52
7.4.270.0000.00816.64
7.4.260.0040.00416.65
7.4.250.0080.00016.58
7.4.240.0020.00716.67
7.4.230.0040.00416.70
7.4.220.0090.00916.75
7.4.210.0000.01516.52
7.4.200.0040.00416.71
7.4.160.0110.00616.73
7.4.150.0110.00817.40
7.4.140.0090.00817.86
7.4.130.0130.00516.61
7.4.120.0130.00816.56
7.4.110.0090.00916.66
7.4.100.0120.00616.36
7.4.90.0070.01016.46
7.4.80.0090.01319.39
7.4.70.0110.01116.67
7.4.60.0060.01216.78
7.4.50.0080.00016.44
7.4.40.0030.01416.63
7.4.30.0070.01016.43
7.4.00.0040.01115.13
7.3.330.0030.00313.29
7.3.320.0030.00313.45
7.3.310.0040.00416.36
7.3.300.0080.00016.43
7.3.290.0030.01416.52
7.3.280.0060.01416.46
7.3.270.0090.01417.40
7.3.260.0030.01516.48
7.3.250.0080.01616.66
7.3.240.0070.01316.45
7.3.230.0140.00316.57
7.3.210.0090.00916.75
7.3.200.0150.00919.39
7.3.190.0030.01316.40
7.3.180.0060.00916.75
7.3.170.0000.02016.75
7.3.160.0080.00816.39
7.3.120.0060.00614.87
7.2.330.0060.01316.70
7.2.320.0040.01516.93
7.2.310.0070.01016.68
7.2.300.0100.00716.95
7.2.290.0090.00916.58
7.2.00.0030.01219.47
7.1.100.0090.00318.03
7.1.70.0030.00616.88
7.1.60.0120.01219.25
7.1.50.0060.01516.66
7.1.00.0070.07322.51
7.0.200.0040.01116.73
7.0.140.0030.07722.18
7.0.60.0200.07721.73
7.0.50.0100.04017.95
7.0.40.0070.09020.13
7.0.30.0270.06720.24
7.0.20.0230.08020.10
7.0.10.0130.08320.06
7.0.00.0030.04320.25
5.6.280.0070.07321.15
5.6.210.0230.07020.80
5.6.200.0070.09018.17
5.6.190.0070.05020.69
5.6.180.0430.04320.34
5.6.170.0370.07720.56
5.6.160.0130.07720.50
5.6.150.0100.07718.21
5.6.140.0100.04018.16
5.6.130.0070.07718.14
5.6.120.0200.08021.07
5.6.110.0030.09021.16
5.6.100.0170.07721.16
5.6.90.0070.09021.01
5.6.80.0070.08320.43
5.5.350.0270.06720.39
5.5.340.0100.03318.00
5.5.330.0100.03720.57
5.5.320.0370.07720.36
5.5.310.0300.07320.34
5.5.300.0100.07718.08
5.5.290.0130.08317.99
5.5.280.0230.07720.82
5.5.270.0030.08720.83
5.5.260.0030.07320.91
5.5.250.0200.07020.52
5.5.240.0230.04020.23
5.4.450.3930.04019.28
5.4.440.0070.04719.44
5.4.430.1530.05319.54
5.4.420.3600.03719.29
5.4.410.3930.04019.17
5.4.400.4100.04319.14
5.4.390.4200.03719.15
5.4.380.4130.04719.13
5.4.370.4000.04019.21
5.4.360.5000.04019.26
5.4.350.3300.03319.22
5.4.340.3970.03319.22
5.4.320.3730.03319.05
5.4.310.4000.04319.13
5.4.300.3900.03719.12
5.4.290.3670.03719.22
5.4.280.4030.03719.05
5.4.270.4400.03719.21
5.4.260.3570.03718.97
5.4.250.4200.03319.04
5.4.240.5200.04319.21
5.4.230.3430.04019.25
5.4.220.4000.03319.12
5.4.210.3970.03019.25
5.4.200.4230.03719.01
5.4.190.0100.05719.21
5.4.180.0100.08019.20
5.4.170.3270.03019.04
5.4.160.2770.03719.02
5.4.150.3600.03019.13
5.4.140.3930.03016.50
5.4.130.3200.03316.38
5.4.120.3000.03716.56
5.4.110.3200.03016.32
5.4.100.2930.03316.41
5.4.90.2770.02716.37
5.4.80.3400.03716.26
5.4.70.0000.04016.51
5.4.60.0030.03716.51
5.4.50.3970.03716.39
5.4.40.3900.04316.36
5.4.30.3670.03716.47
5.4.20.3970.03316.58
5.4.10.3870.03316.54
5.4.00.3930.02715.91
5.3.290.3570.03314.89
5.3.280.4100.04314.75
5.3.270.4830.04014.84
5.3.260.2570.04314.78
5.3.250.3870.03314.79
5.3.240.3770.03714.91
5.3.230.3030.03714.79
5.3.220.3670.04314.62
5.3.210.3330.05014.65
5.3.200.3070.03714.65
5.3.190.2730.04014.80
5.3.180.2970.03714.77
5.3.170.0630.04014.74
5.3.160.0300.04314.73
5.3.150.3430.03714.80
5.3.140.4070.03714.71
5.3.130.3830.03714.74
5.3.120.4000.02714.74
5.3.110.3970.03014.72
5.3.100.4770.03714.12
5.3.90.4730.04014.23
5.3.80.4730.04014.08
5.3.70.4300.04014.14
5.3.60.4700.03014.30
5.3.50.4570.04314.07
5.3.40.3900.04314.18
5.3.30.4000.04014.07
5.3.20.4400.04014.00
5.3.10.4870.03013.85
5.3.00.4570.02713.83
5.2.170.4030.03011.30
5.2.160.3200.02311.11
5.2.150.3400.03311.11
5.2.140.3370.03311.14
5.2.130.3670.02011.10
5.2.120.4030.03311.02
5.2.110.4100.02711.18
5.2.100.4230.03711.25
5.2.90.3500.02311.07
5.2.80.3330.03311.24
5.2.70.4130.02311.09
5.2.60.3770.02711.08
5.2.50.3670.02710.96
5.2.40.3030.03011.03
5.2.30.3230.03011.00
5.2.20.3100.02310.85
5.2.10.3300.02710.82
5.2.00.3400.02710.71
5.1.60.3170.01710.01
5.1.50.2900.03010.08
5.1.40.2930.0239.90
5.1.30.3370.01710.30
5.1.20.2830.02710.35
5.1.10.2370.02310.11
5.1.00.2600.03010.13
5.0.50.1530.0238.53
5.0.40.1270.0178.38
5.0.30.1130.0338.14
5.0.20.1400.0138.20
5.0.10.1570.0208.18
5.0.00.1300.0338.23
4.4.90.1730.0177.05
4.4.80.1570.0107.05
4.4.70.1270.0207.05
4.4.60.1670.0137.05
4.4.50.1930.0207.05
4.4.40.1400.0237.05
4.4.30.1630.0177.05
4.4.20.1230.0177.05
4.4.10.1430.0107.05
4.4.00.1400.0277.05
4.3.110.1400.0177.05
4.3.100.1300.0137.05
4.3.90.1530.0177.05
4.3.80.1430.0237.05
4.3.70.1700.0107.05
4.3.60.1700.0177.05
4.3.50.1770.0177.05
4.3.40.1800.0207.05
4.3.30.0930.0177.05
4.3.20.1100.0207.05
4.3.10.0800.0177.05
4.3.00.1070.0207.05

preferences:
51.38 ms | 401 KiB | 5 Q