3v4l.org

run code in 300+ PHP versions simultaneously
<?php function do_split($name) { return preg_split('/([A-Z]{2,}|([A-Z][^A-Z]*))/', $name, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); } function convert_case($name) { return implode( '_', array_map( 'strtolower', do_split($name) ) ); } function convert_case2($in) { $len = strlen($in); if ($len < 2) { return strtolower($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 = ''; $find_start = function () use (&$char, $alpha_num, $next) { while (!$alpha_num($char)) { if (!$next()) { return null; } } echo "START: $char"; return null; }; $state = $find_start; while ($state !== null) { $state = $state(); } return strtolower($out); } convert_case2('FooBARbar0123'); $samples = array( 'FooBar', 'FooBAR', 'FOOBar', 'foo_bar', 'FOO_bar', 'FOO_Bar', 'foo_BAR', 'foo_Bar', 'Foo_bar', ); print_r(array_map(function ($name) { return array( 'name' => $name, 'converted' => convert_case2($name), // 'converted' => convert_case($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.00618.43
8.3.50.0110.00921.91
8.3.40.0090.00618.67
8.3.30.0110.00419.22
8.3.20.0060.00320.38
8.3.10.0050.00321.54
8.3.00.0080.00017.68
8.2.180.0070.01118.54
8.2.170.0130.00722.96
8.2.160.0100.00720.46
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0040.01126.16
8.2.120.0000.00821.02
8.2.110.0050.00520.47
8.2.100.0080.00318.28
8.2.90.0060.00319.21
8.2.80.0000.00817.97
8.2.70.0050.00517.63
8.2.60.0030.00517.93
8.2.50.0030.00618.07
8.2.40.0060.00318.34
8.2.30.0040.00418.38
8.2.20.0050.00317.78
8.2.10.0070.00018.03
8.2.00.0050.00317.67
8.1.280.0000.01525.92
8.1.270.0070.00023.96
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0000.01023.82
8.1.230.0030.00719.10
8.1.220.0030.00517.76
8.1.210.0040.00418.77
8.1.200.0040.00417.35
8.1.190.0030.00617.35
8.1.180.0000.00818.10
8.1.170.0000.00818.46
8.1.160.0000.00722.09
8.1.150.0040.00418.82
8.1.140.0030.00517.39
8.1.130.0030.00317.73
8.1.120.0040.00417.50
8.1.110.0000.00717.45
8.1.100.0070.00017.46
8.1.90.0000.00717.41
8.1.80.0000.00717.43
8.1.70.0000.00717.48
8.1.60.0000.00817.51
8.1.50.0030.00517.44
8.1.40.0000.00817.60
8.1.30.0040.00417.67
8.1.20.0000.00817.53
8.1.10.0000.00717.65
8.1.00.0000.00817.58
8.0.300.0070.00018.77
8.0.290.0000.00716.75
8.0.280.0030.00318.57
8.0.270.0000.00717.27
8.0.260.0000.00617.20
8.0.250.0000.00716.82
8.0.240.0040.00416.97
8.0.230.0030.00317.00
8.0.220.0000.00716.94
8.0.210.0030.00316.88
8.0.200.0030.00716.98
8.0.190.0000.00716.82
8.0.180.0040.00416.83
8.0.170.0040.00416.90
8.0.160.0000.00716.90
8.0.150.0050.00516.96
8.0.140.0030.00616.77
8.0.130.0000.00613.28
8.0.120.0080.00016.88
8.0.110.0000.00716.80
8.0.100.0040.00416.87
8.0.90.0000.00816.78
8.0.80.0000.01516.89
8.0.70.0000.00716.82
8.0.60.0070.00016.95
8.0.50.0030.00516.95
8.0.30.0100.01117.01
8.0.20.0080.01117.40
8.0.10.0040.00416.93
8.0.00.0150.00316.76
7.4.330.0030.00315.00
7.4.320.0030.00316.47
7.4.300.0070.00016.63
7.4.290.0030.00616.61
7.4.280.0030.00516.42
7.4.270.0040.00316.53
7.4.260.0070.00016.44
7.4.250.0040.00416.58
7.4.240.0050.00216.60
7.4.230.0030.00316.38
7.4.220.0070.01416.70
7.4.210.0060.00916.66
7.4.200.0050.00316.71
7.4.160.0100.01016.40
7.4.150.0090.00917.40
7.4.140.0050.01217.86
7.4.130.0110.00916.53
7.4.120.0080.01016.45
7.4.110.0140.00316.66
7.4.100.0100.01016.52
7.4.90.0070.01016.47
7.4.80.0090.00919.39
7.4.70.0120.01216.38
7.4.60.0060.01016.45
7.4.50.0040.00416.46
7.4.40.0090.00916.20
7.4.30.0100.00716.43
7.4.00.0030.01314.98
7.3.330.0060.00013.37
7.3.320.0030.00313.41
7.3.310.0030.00316.28
7.3.300.0000.00716.21
7.3.290.0070.01116.46
7.3.280.0090.01016.42
7.3.270.0070.01017.40
7.3.260.0140.00416.30
7.3.250.0070.01516.51
7.3.240.0080.01116.40
7.3.230.0140.00416.67
7.3.210.0030.01516.55
7.3.200.0030.01419.39
7.3.190.0070.01416.35
7.3.180.0090.00616.39
7.3.170.0040.02016.65
7.3.160.0100.00716.45
7.3.120.0040.01215.04
7.3.110.0070.01014.60
7.3.100.0140.00015.02
7.3.90.0040.01414.82
7.3.80.0040.01114.79
7.3.70.0040.01114.95
7.3.60.0190.00014.60
7.3.50.0040.00715.00
7.3.40.0070.00714.94
7.3.30.0070.00714.80
7.3.20.0100.01016.45
7.3.10.0050.00716.67
7.3.00.0080.00616.60
7.2.330.0140.00516.89
7.2.320.0030.01416.88
7.2.310.0060.00916.76
7.2.300.0130.01416.90
7.2.290.0090.01216.50
7.2.250.0040.01215.32
7.2.240.0130.00715.38
7.2.230.0030.00915.16
7.2.220.0000.01515.31
7.2.210.0080.00415.18
7.2.200.0060.01315.00
7.2.190.0030.01715.20
7.2.180.0040.00815.15
7.2.170.0030.01215.26
7.2.130.0090.00617.08
7.2.120.0090.00617.08
7.2.110.0100.00616.89
7.2.100.0000.01217.08
7.2.90.0100.00316.93
7.2.80.0060.00916.96
7.2.70.0000.01416.79
7.2.60.0080.00516.86
7.2.50.0070.01017.09
7.2.40.0040.01117.10
7.2.30.0030.01217.01
7.2.20.0040.00717.14
7.2.10.0070.01016.95
7.2.00.0090.00916.91
7.1.330.0060.00915.95
7.1.320.0100.01015.71
7.1.310.0060.00915.86
7.1.300.0110.00015.73
7.1.290.0060.00615.75
7.1.280.0070.00415.91
7.1.270.0060.01315.57
7.1.260.0050.00615.64
7.1.250.0040.00715.95
7.1.100.0080.00818.11
7.1.70.0040.00417.38
7.1.60.0100.01619.25
7.1.50.0060.01316.96
7.1.00.0100.07022.36
7.0.200.0030.00516.73
7.0.140.0030.07021.95
7.0.60.0030.06020.05
7.0.50.0130.04717.90
7.0.40.0070.08320.02
7.0.30.0270.06320.12
7.0.20.0200.05720.19
7.0.10.0030.08020.03
7.0.00.0100.05020.23
5.6.280.0070.07020.81
5.6.210.0100.07720.55
5.6.200.0000.07718.23
5.6.190.0100.07320.40
5.6.180.0330.07020.48
5.6.170.0200.07020.47
5.6.160.0170.07320.57
5.6.150.0100.08018.19
5.6.140.0070.07018.18
5.6.130.0100.07318.16
5.6.120.0130.05021.15
5.6.110.0030.09021.03
5.6.100.0170.08021.01
5.6.90.0100.07721.13
5.6.80.0070.08720.55
5.5.350.0270.07720.46
5.5.340.0170.07318.09
5.5.330.0070.05320.33
5.5.320.0200.03720.31
5.5.310.0400.06720.34
5.5.300.0100.06017.99
5.5.290.0070.08018.02
5.5.280.0130.06020.80
5.5.270.0070.04020.87
5.5.260.0130.08320.78
5.5.250.0200.07020.80
5.5.240.0030.06320.34
5.4.450.0870.05019.69
5.4.440.0330.05719.56
5.4.430.0230.05019.58
5.4.420.0330.04319.44
5.4.410.0200.05719.51
5.4.400.0100.06019.34
5.4.390.0170.05319.32
5.4.380.0130.05318.77
5.4.370.0100.04018.79
5.4.360.0170.04718.54
5.4.350.0080.04312.05
5.4.340.0020.04212.04
5.4.320.0110.03612.52
5.4.310.0210.07212.53
5.4.300.0130.05112.53
5.4.290.0070.05312.52
5.4.280.0200.06612.42
5.4.270.0270.10612.42
5.4.260.0130.07712.42
5.4.250.0130.06112.42
5.4.240.0120.09412.42
5.4.230.0180.05512.41
5.4.220.0240.10812.41
5.4.210.0200.09212.41
5.4.200.0120.05412.41
5.4.190.0230.10612.41
5.4.180.0290.11412.41
5.4.170.0200.12912.43
5.4.160.0170.10112.42
5.4.150.0070.05712.41
5.4.140.0160.05412.10
5.4.130.0130.05112.09
5.4.120.0080.04912.04
5.4.110.0090.05012.04
5.4.100.0180.06212.04
5.4.90.0150.05712.04
5.4.80.0080.05512.04
5.4.70.0130.05412.04
5.4.60.0070.06112.04
5.4.50.0130.05112.04
5.4.40.0120.05112.02
5.4.30.0100.05212.02
5.4.20.0120.05112.02
5.4.10.0110.05312.02
5.4.00.0090.05911.51
5.3.290.0070.04312.80
5.3.280.0140.05312.71
5.3.270.0220.05612.72
5.3.260.0120.05412.73
5.3.250.0140.05412.73
5.3.240.0100.05312.73
5.3.230.0120.04812.72
5.3.220.0130.03912.69
5.3.210.0130.04312.69
5.3.200.0120.04812.69
5.3.190.0110.04012.70
5.3.180.0090.04212.69
5.3.170.0080.04712.69
5.3.160.0110.04112.69
5.3.150.0070.04012.68
5.3.140.0110.04112.68
5.3.130.0100.04712.67
5.3.120.0090.03912.67
5.3.110.0110.03912.67
5.3.100.0160.03112.16
5.3.90.0130.03312.14
5.3.80.0110.04012.13
5.3.70.0100.04112.13
5.3.60.0110.04112.11
5.3.50.0120.04912.06
5.3.40.0110.05012.06
5.3.30.0190.04512.02
5.3.20.0450.04911.80
5.3.10.0190.05711.77
5.3.00.0220.06411.76
5.2.170.0180.0569.23
5.2.160.0140.0689.23
5.2.150.0070.0519.23
5.2.140.0050.0509.22
5.2.130.0090.0479.19
5.2.120.0100.0429.19
5.2.110.0110.0359.19
5.2.100.0090.0369.19
5.2.90.0060.0379.18
5.2.80.0090.0439.18
5.2.70.0150.0359.18
5.2.60.0120.0379.14
5.2.50.0080.0419.12
5.2.40.0120.0289.09
5.2.30.0080.0349.06
5.2.20.0090.0349.04
5.2.10.0040.0368.95
5.2.00.0060.0618.82
5.1.60.0030.0348.10
5.1.50.0020.0318.10
5.1.40.0050.0298.08
5.1.30.0090.0248.43
5.1.20.0050.0428.45
5.1.10.0150.0438.18
5.1.00.0070.0388.17
5.0.50.0060.0286.65
5.0.40.0080.0336.51
5.0.30.0070.0396.32
5.0.20.0050.0206.29
5.0.10.0050.0206.27
5.0.00.0030.0326.26
4.4.90.0030.0184.78
4.4.80.0040.0144.76
4.4.70.0050.0164.75
4.4.60.0020.0174.75
4.4.50.0050.0134.77
4.4.40.0040.0264.71
4.4.30.0040.0154.76
4.4.20.0020.0184.85
4.4.10.0020.0204.85
4.4.00.0040.0244.76
4.3.110.0050.0144.67
4.3.100.0030.0154.66
4.3.90.0040.0204.63
4.3.80.0030.0314.59
4.3.70.0030.0154.63
4.3.60.0030.0154.63
4.3.50.0050.0284.63
4.3.40.0030.0284.54
4.3.30.0020.0213.31
4.3.20.0030.0193.29
4.3.10.0080.0163.25
4.3.00.0130.0207.16

preferences:
41.02 ms | 401 KiB | 5 Q