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', 'FOO_bar_123', 'FOO_Bar_123', 'foo_BAR_123', 'foo_Bar_123', 'Foo_bar_123', ); 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.0110.01118.64
8.3.50.0090.00921.98
8.3.40.0060.01018.98
8.3.30.0120.00319.21
8.3.20.0070.00720.19
8.3.10.0040.00421.77
8.3.00.0040.01418.04
8.2.180.0140.00716.46
8.2.170.0070.00722.96
8.2.160.0140.00720.27
8.2.150.0050.00324.18
8.2.140.0030.00524.66
8.2.130.0090.00026.16
8.2.120.0150.00420.99
8.2.110.0090.00020.52
8.2.100.0090.00319.77
8.2.90.0040.00418.21
8.2.80.0040.00417.97
8.2.70.0080.00017.75
8.2.60.0000.00818.05
8.2.50.0030.00618.07
8.2.40.0030.00618.16
8.2.30.0050.00318.46
8.2.20.0030.00517.84
8.2.10.0000.00718.18
8.2.00.0040.00417.76
8.1.280.0000.01525.92
8.1.270.0030.00623.96
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00322.32
8.1.230.0090.00320.98
8.1.220.0000.00817.77
8.1.210.0050.00319.02
8.1.200.0000.00917.24
8.1.190.0040.00417.36
8.1.180.0030.00618.10
8.1.170.0040.00418.78
8.1.160.0000.00822.04
8.1.150.0040.00418.90
8.1.140.0070.00017.46
8.1.130.0000.00817.96
8.1.120.0000.00717.62
8.1.110.0090.00017.44
8.1.100.0040.00417.46
8.1.90.0000.00717.56
8.1.80.0030.00617.57
8.1.70.0000.00717.48
8.1.60.0040.00417.61
8.1.50.0040.00417.52
8.1.40.0000.00817.55
8.1.30.0040.00417.78
8.1.20.0040.00417.66
8.1.10.0080.00017.67
8.1.00.0030.00517.61
8.0.300.0040.00420.29
8.0.290.0040.00417.00
8.0.280.0040.00418.45
8.0.270.0030.00317.33
8.0.260.0060.00017.29
8.0.250.0080.00017.20
8.0.240.0000.00717.15
8.0.230.0040.00417.11
8.0.220.0000.00717.04
8.0.210.0030.00417.04
8.0.200.0060.00317.04
8.0.190.0040.00417.16
8.0.180.0050.00317.02
8.0.170.0030.00516.98
8.0.160.0000.00717.05
8.0.150.0050.00316.94
8.0.140.0070.00317.04
8.0.130.0000.00613.59
8.0.120.0000.00817.06
8.0.110.0000.00816.98
8.0.100.0050.00216.96
8.0.90.0040.00417.13
8.0.80.0120.00917.01
8.0.70.0000.00817.11
8.0.60.0000.00916.97
8.0.50.0040.00417.11
8.0.30.0110.00817.32
8.0.20.0080.01117.40
8.0.10.0000.00717.21
8.0.00.0150.00316.74
7.4.330.0030.00315.00
7.4.320.0030.00316.65
7.4.300.0000.00716.61
7.4.290.0000.00716.61
7.4.280.0070.00016.71
7.4.270.0040.00416.67
7.4.260.0070.00016.68
7.4.250.0080.00016.56
7.4.240.0040.00416.51
7.4.230.0000.00816.74
7.4.220.0060.01316.62
7.4.210.0160.00016.63
7.4.200.0000.00816.70
7.4.160.0080.00816.57
7.4.150.0170.00017.40
7.4.140.0090.00917.86
7.4.130.0130.00416.77
7.4.120.0100.00816.73
7.4.110.0060.01116.70
7.4.100.0040.01416.61
7.4.90.0150.00916.67
7.4.80.0200.00319.39
7.4.70.0250.00016.46
7.4.60.0060.01016.75
7.4.50.0050.00016.80
7.4.40.0100.00616.65
7.4.30.0100.00716.66
7.4.00.0060.01014.87
7.3.330.0060.00013.32
7.3.320.0000.00513.29
7.3.310.0000.00716.57
7.3.300.0020.00516.38
7.3.290.0000.01416.49
7.3.280.0080.01016.48
7.3.270.0170.01217.40
7.3.260.0150.00316.46
7.3.250.0120.00716.47
7.3.240.0070.01116.47
7.3.230.0120.00616.53
7.3.210.0110.00716.44
7.3.200.0060.01019.39
7.3.190.0140.00816.48
7.3.180.0080.00816.48
7.3.170.0120.00916.58
7.3.160.0060.00916.62
7.3.120.0090.00914.97
7.3.110.0060.00914.92
7.3.100.0080.00514.82
7.3.90.0030.01314.76
7.3.80.0060.00614.78
7.3.70.0140.00315.00
7.3.60.0040.00414.88
7.3.50.0040.00414.69
7.3.40.0030.01314.86
7.3.30.0100.00314.83
7.3.20.0080.00416.25
7.3.10.0070.01016.55
7.3.00.0000.01516.59
7.2.330.0110.00716.93
7.2.320.0090.00916.64
7.2.310.0090.00916.71
7.2.300.0090.01516.56
7.2.290.0070.01016.96
7.2.240.0040.01515.26
7.2.230.0100.00715.40
7.2.220.0130.00615.26
7.2.210.0070.01115.01
7.2.200.0040.01115.11
7.2.190.0090.00615.22
7.2.180.0100.00714.86
7.2.170.0060.00915.28
7.2.160.0070.01115.10
7.2.150.0000.01116.88
7.2.140.0130.00317.09
7.2.130.0080.00417.04
7.2.120.0030.00716.78
7.2.110.0070.00316.90
7.2.100.0030.00716.89
7.2.90.0100.01016.87
7.2.80.0040.00816.57
7.2.70.0000.01317.08
7.2.60.0030.01017.13
7.2.50.0040.01117.15
7.2.40.0080.00816.96
7.2.30.0060.00617.00
7.2.20.0030.00716.80
7.2.10.0100.00717.13
7.2.00.0050.00818.07
7.1.330.0070.01015.53
7.1.320.0150.00315.79
7.1.310.0030.01215.91
7.1.300.0070.00715.86
7.1.290.0180.00015.89
7.1.280.0140.00015.82
7.1.270.0040.00715.95
7.1.260.0080.00715.96
7.1.250.0070.00715.63
7.1.100.0030.00918.19
7.1.70.0070.00717.13
7.1.60.0060.01919.25
7.1.50.0100.00717.06
7.1.00.0030.07722.48
7.0.200.0030.00616.75
7.0.140.0030.07322.08
7.0.60.0130.07719.86
7.0.50.0070.06717.96
7.0.40.0130.03720.09
7.0.30.0330.07020.23
7.0.20.0170.05020.09
7.0.10.0030.07720.17
7.0.00.0100.09020.20
5.6.210.0100.06020.52
5.6.200.0130.04718.26
5.6.190.0170.04720.42
5.6.180.0230.08320.55
5.6.170.0170.08320.55
5.6.160.0000.04320.47
5.6.150.0030.04318.19
5.6.140.0100.07018.27
5.6.130.0070.04018.16
5.6.120.0100.04721.10
5.6.110.0100.08321.02
5.6.100.0130.07321.18
5.6.90.0100.08721.14
5.6.80.0130.05320.57
5.5.350.4130.03720.52
5.5.340.0070.08017.99
5.5.330.0130.07320.41
5.5.320.0230.04020.20
5.5.310.0230.04720.36
5.5.300.0000.06717.94
5.5.290.0130.07318.02
5.5.280.0100.05320.70
5.5.270.0030.05020.94
5.5.260.0130.07720.72
5.5.250.0200.05320.74
5.5.240.0000.08020.40
5.4.450.0330.04719.47
5.4.440.0230.04719.48
5.4.430.0330.05019.16
5.4.420.0500.04719.39
5.4.410.0230.04719.18
5.4.400.0530.04319.09
5.4.390.0200.05019.32
5.4.380.0200.05318.69
5.4.370.0130.06018.77
5.4.360.0030.06318.68
5.4.350.0200.05318.87
5.4.340.0130.05318.71
5.4.320.0140.03712.63
5.4.310.0090.03912.63
5.4.300.0110.03712.63
5.4.290.0070.04212.63
5.4.280.0060.03912.53
5.4.270.0040.04112.52
5.4.260.0160.04412.53
5.4.250.0130.04812.53
5.4.240.0120.05012.52
5.4.230.0150.05012.51
5.4.220.0080.04112.51
5.4.210.0080.03912.52
5.4.200.0060.04212.52
5.4.190.0100.03612.52
5.4.180.0080.03712.52
5.4.170.0070.03912.53
5.4.160.0140.03412.52
5.4.150.0110.03912.51
5.4.140.0080.03912.20
5.4.130.0040.04112.19
5.4.120.0140.03012.14
5.4.110.0100.03512.14
5.4.100.0100.03412.14
5.4.90.0090.03812.14
5.4.80.0130.03312.14
5.4.70.0050.03812.14
5.4.60.0110.03312.14
5.4.50.0080.03712.13
5.4.40.0070.03612.13
5.4.30.0100.03412.13
5.4.20.0090.03612.12
5.4.10.0080.03612.12
5.4.00.0080.03811.61
5.3.290.0140.04112.91
5.3.280.0100.04612.83
5.3.270.0110.04112.84
5.3.260.0110.03812.84
5.3.250.0100.03812.85
5.3.240.0110.03712.85
5.3.230.0080.04112.84
5.3.220.0110.03612.80
5.3.210.0090.04012.80
5.3.200.0090.03712.80
5.3.190.0110.04512.80
5.3.180.0070.04412.80
5.3.170.0110.03612.80
5.3.160.0070.04212.80
5.3.150.0090.03712.80
5.3.140.0090.03612.79
5.3.130.0060.04212.79
5.3.120.0100.04012.79
5.3.110.0080.04112.79
5.3.100.0050.04212.28
5.3.90.0120.03512.26
5.3.80.0070.03912.25
5.3.70.0090.03712.25
5.3.60.0040.04112.23
5.3.50.0080.03812.18
5.3.40.0080.03912.18
5.3.30.0080.03512.14
5.3.20.0140.03111.92
5.3.10.0130.04111.89
5.3.00.0070.04211.87
5.2.170.0060.0329.22
5.2.160.0060.0309.21
5.2.150.0090.0399.21
5.2.140.0050.0419.22
5.2.130.0090.0379.18
5.2.120.0050.0379.18
5.2.110.0070.0379.18
5.2.100.0050.0409.18
5.2.90.0080.0389.18
5.2.80.0040.0349.18
5.2.70.0060.0289.18
5.2.60.0030.0319.13
5.2.50.0050.0319.09
5.2.40.0040.0329.07
5.2.30.0040.0329.05
5.2.20.0070.0279.05
5.2.10.0040.0308.95
5.2.00.0030.0318.81
5.1.60.0060.0228.09
5.1.50.0050.0248.08
5.1.40.0010.0288.07
5.1.30.0060.0258.42
5.1.20.0070.0258.44
5.1.10.0030.0278.16
5.1.00.0120.0298.17
5.0.50.0040.0206.65
5.0.40.0030.0206.51
5.0.30.0030.0326.31
5.0.20.0040.0196.28
5.0.10.0050.0186.27
5.0.00.0000.0356.25
4.4.90.0020.0164.78
4.4.80.0040.0154.76
4.4.70.0030.0154.75
4.4.60.0030.0154.75
4.4.50.0030.0154.77
4.4.40.0030.0254.70
4.4.30.0030.0164.75
4.4.20.0030.0154.84
4.4.10.0040.0144.85
4.4.00.0040.0254.76
4.3.110.0040.0194.67
4.3.100.0050.0154.67
4.3.90.0040.0204.63
4.3.80.0040.0294.59
4.3.70.0060.0174.63
4.3.60.0040.0194.63
4.3.50.0050.0194.63
4.3.40.0050.0294.54
4.3.30.0030.0183.30
4.3.20.0040.0143.28
4.3.10.0020.0153.25
4.3.00.0230.01315.25

preferences:
48.18 ms | 401 KiB | 5 Q