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; } print_r(array_map(function ($in) { return array( 'in' => $in, 'out' => find_words($in), ); }, 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', )));

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.0140.00718.14
8.3.50.0100.00821.98
8.3.40.0090.00618.92
8.3.30.0070.00719.34
8.3.20.0040.00420.52
8.3.10.0060.00321.73
8.3.00.0030.00718.04
8.2.180.0090.01218.41
8.2.170.0060.00922.96
8.2.160.0170.00320.51
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00421.09
8.2.110.0030.00722.10
8.2.100.0090.00320.01
8.2.90.0040.00419.43
8.2.80.0080.00017.97
8.2.70.0040.00417.75
8.2.60.0040.00418.18
8.2.50.0030.00518.07
8.2.40.0040.00418.34
8.2.30.0040.00418.28
8.2.20.0000.00817.88
8.2.10.0080.00018.30
8.2.00.0030.00518.03
8.1.280.0120.00325.92
8.1.270.0040.00423.82
8.1.260.0000.00826.35
8.1.250.0060.00328.09
8.1.240.0090.00022.23
8.1.230.0000.01119.13
8.1.220.0080.00017.76
8.1.210.0000.00818.77
8.1.200.0000.00917.50
8.1.190.0030.00517.35
8.1.180.0000.00918.10
8.1.170.0040.00418.63
8.1.160.0040.00422.23
8.1.150.0040.00418.90
8.1.140.0000.00717.53
8.1.130.0000.00817.86
8.1.120.0050.00317.49
8.1.110.0050.00517.55
8.1.100.0040.00417.47
8.1.90.0000.00817.57
8.1.80.0060.00317.48
8.1.70.0000.00717.54
8.1.60.0050.00517.71
8.1.50.0000.00817.68
8.1.40.0040.00417.49
8.1.30.0000.00817.68
8.1.20.0040.00417.64
8.1.10.0040.00417.73
8.1.00.0050.00317.62
8.0.300.0000.00718.77
8.0.290.0040.00416.74
8.0.280.0030.00318.60
8.0.270.0080.00017.36
8.0.260.0030.00317.38
8.0.250.0030.00317.00
8.0.240.0000.00717.03
8.0.230.0040.00417.11
8.0.220.0030.00317.04
8.0.210.0030.00316.92
8.0.200.0060.00317.04
8.0.190.0000.00817.13
8.0.180.0040.00417.10
8.0.170.0040.00416.99
8.0.160.0000.00817.07
8.0.150.0040.00417.04
8.0.140.0040.00417.07
8.0.130.0060.00013.47
8.0.120.0030.00516.92
8.0.110.0080.00017.00
8.0.100.0080.00016.94
8.0.90.0030.00517.10
8.0.80.0030.01317.01
8.0.70.0040.00417.02
8.0.60.0020.00516.94
8.0.50.0000.00717.14
8.0.30.0070.01217.35
8.0.20.0110.00817.40
8.0.10.0030.00517.00
8.0.00.0100.00816.91
7.4.330.0050.00015.07
7.4.320.0060.00016.61
7.4.300.0030.00316.60
7.4.290.0070.00016.70
7.4.280.0030.00316.59
7.4.270.0040.00416.68
7.4.260.0070.00016.61
7.4.250.0080.00016.47
7.4.240.0040.00416.74
7.4.230.0030.00316.50
7.4.220.0150.00316.81
7.4.210.0040.01816.66
7.4.200.0000.00716.52
7.4.160.0140.01116.73
7.4.150.0090.00917.40
7.4.140.0100.00917.86
7.4.130.0090.00716.67
7.4.120.0080.01016.71
7.4.110.0030.01416.48
7.4.100.0150.00316.41
7.4.90.0110.00716.47
7.4.80.0160.00619.39
7.4.70.0120.01216.48
7.4.60.0070.01016.57
7.4.50.0040.00416.59
7.4.40.0130.00416.50
7.4.30.0070.01016.80
7.4.10.0000.01914.98
7.4.00.0070.00915.11
7.3.330.0030.00313.43
7.3.320.0000.00513.54
7.3.310.0040.00416.52
7.3.300.0000.00716.41
7.3.290.0030.01216.38
7.3.280.0100.00916.44
7.3.270.0160.01017.40
7.3.260.0090.00816.68
7.3.250.0110.01116.46
7.3.240.0060.01216.75
7.3.230.0060.01116.54
7.3.210.0150.00916.50
7.3.200.0090.00919.39
7.3.190.0120.00616.57
7.3.180.0080.00816.42
7.3.170.0090.01316.55
7.3.160.0090.00616.63
7.3.130.0080.00814.98
7.3.120.0070.01014.92
7.3.110.0080.01014.95
7.3.100.0010.01015.04
7.3.90.0100.00514.96
7.3.80.0100.00215.00
7.3.70.0030.00914.91
7.3.60.0100.00714.88
7.3.50.0030.01014.99
7.3.40.0060.00614.97
7.3.30.0100.00514.91
7.3.20.0010.01116.77
7.3.10.0050.00716.50
7.3.00.0030.01116.54
7.2.330.0120.01216.60
7.2.320.0070.01116.87
7.2.310.0110.00716.85
7.2.300.0080.00816.83
7.2.290.0070.01116.71
7.2.260.0100.01015.11
7.2.250.0060.00915.15
7.2.240.0080.00915.21
7.2.230.0050.00715.19
7.2.220.0080.01015.12
7.2.210.0050.00815.07
7.2.200.0060.00815.12
7.2.190.0020.01315.03
7.2.180.0050.01015.23
7.2.170.0080.00615.20
7.2.160.0000.01515.15
7.2.150.0060.00316.91
7.2.140.0070.00717.06
7.2.130.0110.00516.88
7.2.120.0070.00916.91
7.2.110.0090.00616.70
7.2.100.0080.00816.92
7.2.90.0060.00816.87
7.2.80.0070.00816.91
7.2.70.0090.00616.81
7.2.60.0070.00916.92
7.2.50.0060.01016.75
7.2.40.0090.00716.89
7.2.30.0090.00816.89
7.2.20.0080.00716.64
7.2.10.0060.00816.88
7.2.00.0070.00916.90
7.1.330.0080.00715.77
7.1.320.0030.01415.94
7.1.310.0080.00515.78
7.1.300.0050.00815.66
7.1.290.0070.00715.64
7.1.280.0070.01015.74
7.1.270.0050.01015.75
7.1.260.0050.00615.94
7.1.250.0070.00715.57
7.1.240.0020.00915.75
7.1.230.0060.00715.70
7.1.220.0040.00815.71
7.1.210.0030.01115.75
7.1.200.0040.01215.67
7.1.190.0070.00815.69
7.1.180.0050.00815.88
7.1.170.0040.00815.75
7.1.160.0060.00615.81
7.1.150.0050.00915.82
7.1.140.0070.00615.72
7.1.130.0060.00815.75
7.1.120.0060.00915.71
7.1.110.0060.00615.73
7.1.100.0020.01016.34
7.1.90.0070.00415.67
7.1.80.0070.00415.70
7.1.70.0040.00616.16
7.1.60.0090.00816.67
7.1.50.0070.00716.09
7.1.40.0060.00615.72
7.1.30.0030.00815.81
7.1.20.0060.00815.76
7.1.10.0080.00315.70
7.1.00.0060.02317.47
7.0.330.0100.00615.33
7.0.320.0040.01215.40
7.0.310.0020.01215.34
7.0.300.0050.00815.32
7.0.290.0080.00615.40
7.0.280.0100.00715.37
7.0.270.0110.00615.33
7.0.260.0040.00915.42
7.0.250.0080.00615.30
7.0.240.0080.00815.33
7.0.230.0050.01115.39
7.0.220.0060.00715.25
7.0.210.0070.00815.46
7.0.200.0060.00915.71
7.0.190.0060.00815.34
7.0.180.0040.01015.39
7.0.170.0060.00715.35
7.0.160.0090.00615.34
7.0.150.0070.00615.48
7.0.140.0070.02517.00
7.0.130.0080.00715.37
7.0.120.0070.00715.36
7.0.110.0050.00715.37
7.0.100.0100.00815.44
7.0.90.0090.00615.40
7.0.80.0030.00915.42
7.0.70.0050.00815.26
7.0.60.0080.01516.55
7.0.50.0090.01416.07
7.0.40.0040.01715.33
7.0.30.0120.02515.08
7.0.20.0160.02315.08
7.0.10.0060.01815.12
7.0.00.0070.02815.10
5.6.400.0030.01414.51
5.6.390.0090.00614.66
5.6.380.0080.00914.38
5.6.370.0040.01214.25
5.6.360.0070.00714.55
5.6.350.0060.00914.44
5.6.340.0060.01414.69
5.6.330.0090.00614.65
5.6.320.0060.00814.12
5.6.310.0070.00614.66
5.6.300.0080.00914.71
5.6.290.0080.00714.39
5.6.280.0060.02616.06
5.6.270.0070.00914.35
5.6.260.0070.00714.36
5.6.250.0010.01414.52
5.6.240.0060.00814.55
5.6.230.0110.00714.49
5.6.220.0080.00814.51
5.6.210.0090.02416.00
5.6.200.0080.02715.48
5.6.190.0060.02816.08
5.6.180.0130.02315.96
5.6.170.0110.01815.90
5.6.160.0080.02515.91
5.6.150.0060.01915.37
5.6.140.0070.02615.37
5.6.130.0080.02115.50
5.6.120.0060.02416.06
5.6.110.0110.02516.21
5.6.100.0070.02916.18
5.6.90.0080.01816.02
5.6.80.0100.02615.87
5.6.70.0090.01014.35
5.6.60.0060.01014.34
5.6.50.0080.00914.19
5.6.40.0090.00714.50
5.6.30.0030.01214.50
5.6.20.0070.00814.52
5.6.10.0030.01414.47
5.6.00.0030.01314.32
5.5.380.0070.00612.41
5.5.370.0040.01112.52
5.5.360.0060.00812.43
5.5.350.1100.01814.31
5.5.340.0040.01713.89
5.5.330.0040.02214.44
5.5.320.0120.01214.31
5.5.310.0180.02114.43
5.5.300.0080.02013.85
5.5.290.0060.02213.88
5.5.280.0060.02414.60
5.5.270.0050.02414.42
5.5.260.0070.02814.54
5.5.250.0070.02714.47
5.5.240.0040.02514.31
5.5.230.0100.00512.30
5.5.220.0060.00712.39
5.5.210.0050.00712.41
5.5.200.0100.00412.41
5.5.190.0080.00612.34
5.5.180.0110.00412.48
5.5.170.0100.00812.38
5.5.160.0090.00812.39
5.5.150.0090.00712.41
5.5.140.0050.01012.46
5.5.130.0060.00712.53
5.5.120.0050.00612.40
5.5.110.0050.00812.43
5.5.100.0040.00812.24
5.5.90.0040.00512.43
5.5.80.0060.00712.42
5.5.70.0050.00612.33
5.5.60.0090.00612.50
5.5.50.0040.00612.47
5.5.40.0070.00812.36
5.5.30.0080.00712.41
5.5.20.0020.00912.44
5.5.10.0060.00712.49
5.5.00.0050.00912.34
5.4.450.0130.01413.52
5.4.440.0150.01613.31
5.4.430.0120.01213.47
5.4.420.0100.01813.32
5.4.410.0060.02013.36
5.4.400.0110.01413.24
5.4.390.0170.01613.27
5.4.380.0130.02313.18
5.4.370.0110.01913.08
5.4.360.0080.01913.23
5.4.350.0050.01913.20
5.4.340.0140.01513.21
5.4.330.0090.00611.34
5.4.320.0090.01311.63
5.4.310.0090.01311.67
5.4.300.0050.01511.61
5.4.290.0040.01711.65
5.4.280.0080.01211.60
5.4.270.0070.01311.54
5.4.260.0050.01511.58
5.4.250.0060.01611.58
5.4.240.0060.01411.57
5.4.230.0070.01411.61
5.4.220.0080.01511.63
5.4.210.0070.01511.59
5.4.200.0050.01611.59
5.4.190.0050.01711.58
5.4.180.0050.01411.54
5.4.170.0080.01611.47
5.4.160.0050.01511.64
5.4.150.0040.01611.66
5.4.140.0070.01611.56
5.4.130.0060.01611.43
5.4.120.0060.01411.51
5.4.110.0090.01211.58
5.4.100.0040.01611.51
5.4.90.0060.01511.48
5.4.80.0060.01611.40
5.4.70.0090.01511.58
5.4.60.0100.01111.48
5.4.50.0090.01211.45
5.4.40.0080.01511.48
5.4.30.0080.01311.46
5.4.20.0080.01311.44
5.4.10.0080.01411.41
5.4.00.0070.01311.23
5.3.290.0080.01711.47
5.3.280.0090.01211.51
5.3.270.0060.01411.53
5.3.260.0090.01511.49
5.3.250.0050.01511.57
5.3.240.0080.01711.42
5.3.230.0060.01511.53
5.3.220.0070.01711.39
5.3.210.0050.01711.46
5.3.200.0050.01611.41
5.3.190.0050.01511.43
5.3.180.0070.01511.44
5.3.170.0080.01311.50
5.3.160.0080.01411.57
5.3.150.0100.01411.51
5.3.140.0060.01611.46
5.3.130.0040.01711.57
5.3.120.0060.01511.40
5.3.110.0070.01511.55
5.3.100.0090.01211.34
5.3.90.0090.01311.25
5.3.80.0100.01311.25
5.3.70.0040.01611.34
5.3.60.0080.01411.27
5.3.50.0070.01711.32
5.3.40.0070.01511.23
5.3.30.0050.01911.34
5.3.20.0060.01411.19
5.3.10.0050.01711.10
5.3.00.0100.01611.14
5.2.170.0050.01310.00
5.2.160.0070.01410.07
5.2.150.0020.01310.06
5.2.140.0020.01710.06
5.2.130.0030.01510.08
5.2.120.0040.01310.00
5.2.110.0030.01610.04
5.2.100.0040.01210.03
5.2.90.0060.01210.02
5.2.80.0060.0119.94
5.2.70.0050.01210.03
5.2.60.0040.0149.98
5.2.50.0030.0139.91
5.2.40.0050.0149.94
5.2.30.0050.0139.96
5.2.20.0020.0129.94
5.2.10.0030.0149.88
5.2.00.0070.0129.72
5.1.60.0020.0139.36
5.1.50.0040.0119.35
5.1.40.0030.0139.39
5.1.30.0040.0139.48
5.1.20.0040.0129.50
5.1.10.0090.0119.38
5.1.00.0070.0109.37
5.0.50.0060.0128.87
5.0.40.0020.0118.82
5.0.30.0030.0148.76
5.0.20.0020.0118.75
5.0.10.0040.0118.74
5.0.00.0020.0168.74
4.4.90.0030.0068.24
4.4.80.0030.0088.24
4.4.70.0040.0068.24
4.4.60.0010.0108.24
4.4.50.0040.0068.24
4.4.40.0030.0118.22
4.4.30.0020.0088.24
4.4.20.0020.0098.27
4.4.10.0070.0078.27
4.4.00.0020.0138.24
4.3.110.0010.0108.21
4.3.100.0030.0078.21
4.3.90.0020.0078.20
4.3.80.0020.0118.18
4.3.70.0030.0078.19
4.3.60.0050.0068.19
4.3.50.0040.0068.19
4.3.40.0030.0118.16
4.3.30.0050.0077.75
4.3.20.0030.0067.74
4.3.10.0000.0097.73
4.3.00.0040.00711.74

preferences:
47.16 ms | 401 KiB | 5 Q