3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_words($in) { // stateful stream functions $len = strlen($in); if ($len === 0) { return array(); // nothing to lex } $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; }; // stateless helper functions $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); }; // lexer states do action and return next lexer state $out = array(); $find_word = null; // cyclic dependency, declare first and pass by reference to dependents $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; }; $find_word = function () use (&$char, $alpha_num, $upper, $lower, $next, $peek, $std_word, $upr_word, $num_word) { // consume all non-alphanumeric characters while (!$alpha_num($char)) { if (!$next()) { return null; // nothing left } } if ($upper($char)) { if ($upper($peek())) { // uppercase word return $upr_word; } return $std_word; // capitalized word } if ($lower($char)) { return $std_word; // lowercase word } return $num_word; // number }; // churn through states $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.0040.01118.43
8.3.50.0100.00722.16
8.3.40.0070.00718.90
8.3.30.0070.00719.14
8.3.20.0080.00020.24
8.3.10.0040.00421.89
8.3.00.0130.00318.16
8.2.180.0070.01016.63
8.2.170.0120.00622.96
8.2.160.0150.00620.64
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0050.00226.16
8.2.120.0110.00320.99
8.2.110.0090.00022.29
8.2.100.0040.00818.22
8.2.90.0080.00019.48
8.2.80.0000.00817.97
8.2.70.0060.00317.75
8.2.60.0100.00018.29
8.2.50.0000.00818.07
8.2.40.0030.00619.74
8.2.30.0000.00718.55
8.2.20.0040.00417.93
8.2.10.0080.00018.11
8.2.00.0050.00518.03
8.1.280.0150.00025.92
8.1.270.0050.00323.82
8.1.260.0070.00026.35
8.1.250.0090.00028.09
8.1.240.0040.00423.92
8.1.230.0060.00619.34
8.1.220.0000.00817.78
8.1.210.0030.00518.77
8.1.200.0090.00017.60
8.1.190.0030.00617.13
8.1.180.0030.00618.10
8.1.170.0030.00518.83
8.1.160.0060.00322.14
8.1.150.0080.00018.87
8.1.140.0080.00017.49
8.1.130.0060.00318.00
8.1.120.0000.00717.48
8.1.110.0040.00417.44
8.1.100.0000.00717.54
8.1.90.0040.00417.62
8.1.80.0000.00717.54
8.1.70.0080.00017.49
8.1.60.0040.00417.73
8.1.50.0030.00617.64
8.1.40.0000.00817.54
8.1.30.0040.00417.74
8.1.20.0000.00817.79
8.1.10.0000.00817.65
8.1.00.0030.00517.51
8.0.300.0070.00018.77
8.0.290.0040.00416.88
8.0.280.0000.00718.62
8.0.270.0040.00417.38
8.0.260.0070.00017.29
8.0.250.0000.00717.13
8.0.240.0040.00417.17
8.0.230.0000.00717.02
8.0.220.0070.00016.96
8.0.210.0030.00316.96
8.0.200.0100.00017.10
8.0.190.0050.00317.20
8.0.180.0070.00017.00
8.0.170.0080.00017.13
8.0.160.0000.00817.05
8.0.150.0020.00516.89
8.0.140.0000.00916.92
8.0.130.0060.00013.43
8.0.120.0030.00516.93
8.0.110.0030.00517.01
8.0.100.0040.00416.87
8.0.90.0050.00317.11
8.0.80.0030.01317.05
8.0.70.0040.00417.12
8.0.60.0000.00717.13
8.0.50.0030.00616.94
8.0.30.0120.00717.31
8.0.20.0080.01017.40
8.0.10.0000.00817.18
8.0.00.0120.00916.81
7.4.330.0030.00315.00
7.4.320.0070.00016.60
7.4.300.0000.00716.55
7.4.290.0080.00016.63
7.4.280.0050.00216.62
7.4.270.0040.00416.69
7.4.260.0000.00716.52
7.4.250.0040.00416.57
7.4.240.0020.00616.70
7.4.230.0030.00516.74
7.4.220.0070.01016.56
7.4.210.0040.01216.78
7.4.200.0040.00316.64
7.4.160.0120.00616.52
7.4.150.0090.00917.40
7.4.140.0090.00817.86
7.4.130.0130.00516.58
7.4.120.0120.00816.71
7.4.110.0070.01116.45
7.4.100.0090.00916.60
7.4.90.0190.00016.86
7.4.80.0100.01019.39
7.4.70.0100.01016.56
7.4.60.0150.00316.66
7.4.50.0000.00716.55
7.4.40.0130.00316.45
7.4.30.0070.01116.59
7.4.10.0090.00915.27
7.4.00.0050.01115.12
7.3.330.0000.00613.42
7.3.320.0000.00613.28
7.3.310.0000.00816.45
7.3.300.0040.00416.51
7.3.290.0030.01016.46
7.3.280.0130.00816.47
7.3.270.0120.01517.40
7.3.260.0070.01016.50
7.3.250.0070.01616.39
7.3.240.0120.00616.61
7.3.230.0070.01016.61
7.3.210.0140.00616.52
7.3.200.0090.01219.39
7.3.190.0100.01316.61
7.3.180.0080.00816.65
7.3.170.0060.01516.78
7.3.160.0120.00616.66
7.3.130.0060.01215.23
7.3.120.0030.01314.91
7.3.110.0130.00314.87
7.3.100.0080.00615.13
7.3.90.0080.00615.07
7.3.80.0120.00314.90
7.3.70.0030.01015.10
7.3.60.0000.01214.96
7.3.50.0100.00714.76
7.3.40.0040.01115.03
7.3.30.0030.01014.97
7.3.20.0140.00016.69
7.3.10.0110.00716.46
7.3.00.0150.00416.38
7.2.330.0090.00916.65
7.2.320.0060.01216.88
7.2.310.0040.01416.88
7.2.300.0100.00916.90
7.2.290.0100.01316.94
7.2.260.0060.01315.40
7.2.250.0110.00715.01
7.2.240.0060.00915.18
7.2.230.0120.00315.43
7.2.220.0080.00414.87
7.2.210.0000.01615.16
7.2.200.0070.01014.86
7.2.190.0100.00715.20
7.2.180.0030.01415.08
7.2.170.0040.01115.19
7.2.160.0100.00715.16
7.2.150.0070.01117.15
7.2.140.0120.00416.70
7.2.130.0100.00616.72
7.2.120.0130.00816.81
7.2.110.0100.00616.81
7.2.100.0110.00716.53
7.2.90.0080.00816.46
7.2.80.0130.00916.84
7.2.70.0120.00716.49
7.2.60.0120.00716.79
7.2.50.0080.00816.68
7.2.40.0070.00816.71
7.2.30.0120.00416.56
7.2.20.0120.00616.70
7.2.10.0150.00416.49
7.2.00.0070.00817.47
7.1.330.0040.01115.79
7.1.320.0000.01615.77
7.1.310.0100.00615.75
7.1.300.0090.00915.88
7.1.290.0100.00315.85
7.1.280.0000.01015.78
7.1.270.0030.01015.87
7.1.260.0070.00415.76
7.1.250.0070.00815.55
7.1.240.0070.01115.93
7.1.230.0030.01215.80
7.1.220.0080.00415.87
7.1.210.0060.01015.69
7.1.200.0060.00715.59
7.1.190.0030.01515.72
7.1.180.0040.00815.68
7.1.170.0070.01015.80
7.1.160.0080.00415.79
7.1.150.0090.00615.73
7.1.140.0030.01315.88
7.1.130.0090.00615.93
7.1.120.0080.00815.79
7.1.110.0030.00615.92
7.1.100.0040.00717.01
7.1.90.0000.01515.78
7.1.80.0000.01515.97
7.1.70.0070.00616.50
7.1.60.0130.00517.48
7.1.50.0040.01416.44
7.1.40.0080.00415.93
7.1.30.0070.00715.75
7.1.20.0120.00815.90
7.1.10.0030.00715.91
7.1.00.0020.04419.23
7.0.330.0000.01515.61
7.0.320.0090.00615.65
7.0.310.0120.00615.45
7.0.300.0150.00415.54
7.0.290.0120.00315.44
7.0.280.0100.00615.46
7.0.270.0070.00715.44
7.0.260.0040.01115.18
7.0.250.0090.00915.34
7.0.240.0070.00715.25
7.0.230.0070.01415.57
7.0.220.0060.00615.27
7.0.210.0070.01015.52
7.0.200.0030.01315.92
7.0.190.0060.00915.22
7.0.180.0030.01315.52
7.0.170.0060.01215.30
7.0.160.0100.01015.25
7.0.150.0120.00015.56
7.0.140.0110.03618.79
7.0.130.0090.00615.55
7.0.120.0080.00815.29
7.0.110.0000.01615.09
7.0.100.0040.01415.49
7.0.90.0070.01015.46
7.0.80.0080.00815.36
7.0.70.0030.01615.60
7.0.60.0070.02518.67
7.0.50.0080.02816.67
7.0.40.0070.02216.73
7.0.30.0130.03716.82
7.0.20.0150.04916.73
7.0.10.0040.02716.81
7.0.00.0050.03316.84
5.6.400.0090.00614.76
5.6.390.0070.01014.32
5.6.380.0110.00814.79
5.6.370.0100.00714.79
5.6.360.0070.01014.29
5.6.350.0060.01314.83
5.6.340.0000.02014.41
5.6.330.0100.01014.57
5.6.320.0080.00814.71
5.6.310.0090.01214.78
5.6.300.0070.01014.50
5.6.290.0050.00814.77
5.6.280.0050.04217.84
5.6.270.0070.01114.85
5.6.260.0090.00914.72
5.6.250.0080.01114.54
5.6.240.0030.01614.55
5.6.230.0070.00714.74
5.6.220.0170.00314.66
5.6.210.0030.04117.63
5.6.200.0070.04816.28
5.6.190.0020.04017.46
5.6.180.0180.04817.56
5.6.170.0150.03717.58
5.6.160.0130.04217.53
5.6.150.0050.03116.38
5.6.140.0070.04816.23
5.6.130.0070.05016.37
5.6.120.0150.03817.68
5.6.110.0080.04317.66
5.6.100.0060.04517.89
5.6.90.0100.04517.74
5.6.80.0020.02917.47
5.6.70.0030.01414.43
5.6.60.0030.01414.23
5.6.50.0080.00814.34
5.6.40.0080.00814.30
5.6.30.0100.00714.30
5.6.20.0130.00314.28
5.6.10.0030.01314.53
5.6.00.0030.01014.36
5.5.380.0060.00914.48
5.5.370.0060.00914.44
5.5.360.0030.01314.21
5.5.350.0080.03617.45
5.5.340.0000.02916.29
5.5.330.0100.03717.35
5.5.320.0120.02717.62
5.5.310.0220.04417.28
5.5.300.0080.04316.24
5.5.290.0090.04216.23
5.5.280.0140.03017.58
5.5.270.0070.04017.57
5.5.260.0090.04517.64
5.5.250.0090.03217.67
5.5.240.0090.04117.22
5.5.230.0150.00614.44
5.5.220.0090.00314.50
5.5.210.0110.00414.47
5.5.200.0060.01014.56
5.5.190.0060.00614.59
5.5.180.0040.00714.52
5.5.170.0140.00314.59
5.5.160.0090.00614.40
5.5.150.0090.01214.23
5.5.140.0070.01314.64
5.5.130.0000.01214.23
5.5.120.0130.00714.24
5.5.110.0040.00814.36
5.5.100.0100.00614.52
5.5.90.0030.01314.30
5.5.80.0030.01014.47
5.5.70.0060.00914.29
5.5.60.0130.00614.44
5.5.50.0070.00714.07
5.5.40.0090.00914.41
5.5.30.0030.01014.44
5.5.20.0100.00314.70
5.5.10.0070.01414.22
5.5.00.0040.01114.47
5.4.450.0100.03016.45
5.4.440.0450.01816.52
5.4.430.0150.02516.43
5.4.420.0250.02216.36
5.4.410.0350.02516.24
5.4.400.0180.02516.25
5.4.390.0200.02916.27
5.4.380.0470.02616.02
5.4.370.0420.03016.10
5.4.360.0690.03716.02
5.4.350.0370.04016.13
5.4.340.0590.02716.05
5.4.330.0000.01613.40
5.4.320.0030.02713.02
5.4.310.0050.02513.02
5.4.300.0090.02213.02
5.4.290.0120.02113.02
5.4.280.0110.02812.97
5.4.270.0100.02812.96
5.4.260.0040.02712.96
5.4.250.0070.02312.97
5.4.240.0050.02612.96
5.4.230.0110.02112.96
5.4.220.0080.02512.96
5.4.210.0040.03012.96
5.4.200.0080.02212.96
5.4.190.0080.02212.96
5.4.180.0080.02312.96
5.4.170.0070.02312.97
5.4.160.0100.02812.96
5.4.150.0060.03012.96
5.4.140.0090.02812.80
5.4.130.0110.02412.80
5.4.120.0120.02712.78
5.4.110.0060.02612.77
5.4.100.0120.02312.77
5.4.90.0070.02612.78
5.4.80.0090.02012.77
5.4.70.0060.02312.77
5.4.60.0110.01812.77
5.4.50.0120.02112.77
5.4.40.0090.02912.77
5.4.30.0070.02812.77
5.4.20.0100.01812.76
5.4.10.0070.02212.76
5.4.00.0080.02012.51
5.3.290.0070.02413.15
5.3.280.0090.02313.12
5.3.270.0100.02213.12
5.3.260.0070.02713.12
5.3.250.0070.02513.13
5.3.240.0070.02213.13
5.3.230.0090.02213.12
5.3.220.0090.02313.11
5.3.210.0100.02113.11
5.3.200.0100.02213.10
5.3.190.0100.02013.11
5.3.180.0070.02313.10
5.3.170.0070.02413.10
5.3.160.0090.02213.10
5.3.150.0070.02713.10
5.3.140.0120.02413.10
5.3.130.0090.02713.10
5.3.120.0110.02713.10
5.3.110.0100.02313.10
5.3.100.0080.02312.84
5.3.90.0060.02212.83
5.3.80.0130.01812.82
5.3.70.0100.02112.83
5.3.60.0090.02612.82
5.3.50.0070.02412.79
5.3.40.0040.02412.79
5.3.30.0040.02212.77
5.3.20.0050.02212.66
5.3.10.0090.02212.65
5.3.00.0070.02212.64
5.2.170.0100.0359.22
5.2.160.0060.0419.22
5.2.150.0040.0339.22
5.2.140.0060.0319.22
5.2.130.0070.0289.18
5.2.120.0030.0319.18
5.2.110.0040.0419.18
5.2.100.0100.0369.18
5.2.90.0050.0319.18
5.2.80.0040.0339.18
5.2.70.0090.0279.18
5.2.60.0070.0409.13
5.2.50.0070.0409.10
5.2.40.0130.0319.07
5.2.30.0040.0379.05
5.2.20.0080.0279.05
5.2.10.0030.0308.95
5.2.00.0060.0298.81
5.1.60.0040.0268.09
5.1.50.0020.0288.09
5.1.40.0040.0258.07
5.1.30.0040.0278.42
5.1.20.0070.0258.44
5.1.10.0050.0268.17
5.1.00.0040.0278.18
5.0.50.0060.0186.64
5.0.40.0030.0206.51
5.0.30.0060.0306.32
5.0.20.0030.0216.29
5.0.10.0030.0256.27
5.0.00.0030.0316.25
4.4.90.0050.0144.78
4.4.80.0030.0154.75
4.4.70.0040.0154.75
4.4.60.0060.0134.75
4.4.50.0020.0164.77
4.4.40.0020.0254.71
4.4.30.0030.0154.76
4.4.20.0040.0154.85
4.4.10.0030.0154.85
4.4.00.0030.0264.76
4.3.110.0020.0174.67
4.3.100.0030.0154.67
4.3.90.0020.0164.64
4.3.80.0030.0254.58
4.3.70.0020.0174.63
4.3.60.0040.0184.63
4.3.50.0050.0144.63
4.3.40.0050.0224.54
4.3.30.0030.0203.30
4.3.20.0020.0203.28
4.3.10.0030.0203.24
4.3.00.0070.01715.25

preferences:
46.65 ms | 401 KiB | 5 Q