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); } $pos = 0; $out = ''; $peek = function() { if ($pos+1 >= $len) { return null; } return $in[$pos+1]; }; $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); }; $start_state = function () { return null; }; $state = $start_state; while ($state !== null) { $state = $state(); } return strtolower($output); } 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.55
8.3.50.0110.00821.99
8.3.40.0070.00718.75
8.3.30.0060.00919.09
8.3.20.0040.00420.16
8.3.10.0070.00021.89
8.3.00.0080.00017.68
8.2.180.0040.01118.46
8.2.170.0110.01119.04
8.2.160.0040.01120.43
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0000.00726.16
8.2.120.0040.00421.05
8.2.110.0030.00622.14
8.2.100.0040.00819.89
8.2.90.0030.00519.22
8.2.80.0050.00517.97
8.2.70.0040.00417.63
8.2.60.0030.00618.05
8.2.50.0000.00918.07
8.2.40.0040.00419.88
8.2.30.0040.00418.29
8.2.20.0040.00417.88
8.2.10.0000.00718.17
8.2.00.0080.00017.79
8.1.280.0120.00325.92
8.1.270.0040.00423.79
8.1.260.0000.00826.35
8.1.250.0000.00728.09
8.1.240.0090.00023.94
8.1.230.0080.00418.97
8.1.220.0080.00017.80
8.1.210.0080.00018.77
8.1.200.0030.00717.38
8.1.190.0000.00817.35
8.1.180.0040.00418.10
8.1.170.0000.00818.51
8.1.160.0000.00822.12
8.1.150.0070.00018.92
8.1.140.0050.00317.42
8.1.130.0070.00017.88
8.1.120.0070.00017.54
8.1.110.0070.00017.50
8.1.100.0060.00317.40
8.1.90.0070.00017.51
8.1.80.0030.00517.42
8.1.70.0030.00317.48
8.1.60.0040.00417.57
8.1.50.0030.00517.63
8.1.40.0040.00417.55
8.1.30.0040.00417.66
8.1.20.0030.00717.71
8.1.10.0060.00317.51
8.1.00.0000.00817.55
8.0.300.0040.00418.77
8.0.290.0000.00716.75
8.0.280.0000.00718.35
8.0.270.0040.00417.17
8.0.260.0000.00617.24
8.0.250.0030.00317.02
8.0.240.0040.00416.96
8.0.230.0040.00416.91
8.0.220.0070.00016.97
8.0.210.0040.00416.99
8.0.200.0060.00017.09
8.0.190.0030.00316.99
8.0.180.0040.00417.03
8.0.170.0060.00317.08
8.0.160.0050.00316.88
8.0.150.0070.00316.85
8.0.140.0040.00416.84
8.0.130.0000.00913.46
8.0.120.0000.00816.98
8.0.110.0000.00717.05
8.0.100.0000.00816.79
8.0.90.0030.00616.82
8.0.80.0070.01416.98
8.0.70.0000.00716.85
8.0.60.0070.00017.01
8.0.50.0040.00416.98
8.0.30.0130.00917.09
8.0.20.0110.00817.40
8.0.10.0040.00417.05
8.0.00.0130.00716.80
7.4.330.0000.00615.01
7.4.320.0030.00316.46
7.4.300.0030.00316.65
7.4.290.0000.00716.61
7.4.280.0040.00416.67
7.4.270.0000.00716.59
7.4.260.0070.00016.62
7.4.250.0040.00416.47
7.4.240.0000.00716.62
7.4.230.0040.00416.73
7.4.220.0200.00716.64
7.4.210.0100.01016.67
7.4.200.0040.00416.66
7.4.160.0070.01016.52
7.4.150.0100.01017.40
7.4.140.0090.01117.86
7.4.130.0080.00816.63
7.4.120.0130.00416.57
7.4.110.0090.00916.60
7.4.100.0130.00616.45
7.4.90.0080.01216.53
7.4.80.0100.01019.39
7.4.70.0070.01016.67
7.4.60.0120.00616.45
7.4.50.0040.00016.34
7.4.40.0000.01816.60
7.4.30.0030.01316.58
7.4.00.0070.01114.91
7.3.330.0030.00313.46
7.3.320.0000.00513.26
7.3.310.0040.00416.36
7.3.300.0050.00216.33
7.3.290.0060.00916.46
7.3.280.0100.00916.42
7.3.270.0100.00717.40
7.3.260.0060.01216.48
7.3.250.0090.00816.60
7.3.240.0100.00916.41
7.3.230.0060.01016.46
7.3.210.0160.00316.67
7.3.200.0080.01119.39
7.3.190.0120.01216.53
7.3.180.0080.00816.70
7.3.170.0090.00916.51
7.3.160.0040.01116.50
7.3.120.0100.00614.88
7.3.110.0100.00715.02
7.3.100.0100.00315.06
7.3.90.0060.00314.85
7.3.80.0070.00314.76
7.3.70.0070.00414.82
7.3.60.0090.00614.92
7.3.50.0110.00714.95
7.3.40.0000.01214.93
7.3.30.0000.01114.86
7.3.20.0070.00716.70
7.3.10.0090.00416.67
7.3.00.0030.00916.74
7.2.330.0040.01516.59
7.2.320.0040.01816.61
7.2.310.0100.01016.88
7.2.300.0110.00516.40
7.2.290.0000.01716.83
7.2.250.0130.00615.08
7.2.240.0130.00715.19
7.2.230.0100.00714.77
7.2.220.0080.00315.33
7.2.210.0040.01115.02
7.2.200.0070.00714.81
7.2.190.0030.01215.02
7.2.180.0030.00815.13
7.2.170.0070.00714.86
7.2.130.0040.01416.86
7.2.120.0030.00617.04
7.2.110.0030.01716.66
7.2.100.0030.01416.70
7.2.90.0070.00717.10
7.2.80.0180.00016.77
7.2.70.0050.00516.95
7.2.60.0090.00716.71
7.2.50.0070.00716.79
7.2.40.0060.00916.87
7.2.30.0070.00416.94
7.2.20.0110.00417.09
7.2.10.0070.01016.94
7.2.00.0030.01218.26
7.1.330.0030.01215.54
7.1.320.0060.00615.75
7.1.310.0060.00615.96
7.1.300.0110.00715.82
7.1.290.0040.00815.66
7.1.280.0070.00315.86
7.1.270.0080.00515.90
7.1.260.0070.00715.57
7.1.250.0090.00315.87
7.1.100.0000.00917.89
7.1.70.0040.00417.21
7.1.60.0080.01519.25
7.1.50.0060.00916.98
7.1.00.0000.07322.57
7.0.200.0080.00016.64
7.0.140.0000.07722.18
7.0.60.0100.07719.80
7.0.50.0100.08017.81
7.0.40.0000.04720.30
7.0.30.0270.06320.09
7.0.20.0330.06720.24
7.0.10.0100.06320.33
7.0.00.0030.05320.09
5.6.280.0030.07321.04
5.6.210.0070.07020.53
5.6.200.0200.07318.25
5.6.190.0030.04320.64
5.6.180.0300.03320.61
5.6.170.0330.04020.55
5.6.160.0100.08720.51
5.6.150.0030.07718.16
5.6.140.0070.08018.24
5.6.130.0170.07718.19
5.6.120.0130.07020.92
5.6.110.0100.08021.00
5.6.100.0100.07720.98
5.6.90.0070.05021.05
5.6.80.0070.07020.39
5.5.350.3030.02720.43
5.5.340.0070.06317.96
5.5.330.0130.07320.29
5.5.320.3400.04720.20
5.5.310.0200.04020.31
5.5.300.0130.08317.97
5.5.290.0070.08318.08
5.5.280.0130.08020.82
5.5.270.0100.08020.86
5.5.260.0070.08320.89
5.5.250.0170.07720.73
5.5.240.0030.07720.09
5.4.450.0500.02719.20
5.4.440.0330.04719.50
5.4.430.0270.04319.59
5.4.420.0600.04319.64
5.4.410.0430.03719.09
5.4.400.0500.03319.32
5.4.390.0300.04319.00
5.4.380.0170.05318.69
5.4.370.0230.05718.71
5.4.360.0230.04318.63
5.4.350.0270.04318.75
5.4.340.0200.05318.75
5.4.320.0030.04012.52
5.4.310.0050.04112.52
5.4.300.0070.03612.52
5.4.290.0100.03512.52
5.4.280.0060.03712.41
5.4.270.0060.04012.41
5.4.260.0050.04912.41
5.4.250.0090.03712.41
5.4.240.0070.03612.41
5.4.230.0070.03912.40
5.4.220.0050.03712.41
5.4.210.0070.03712.41
5.4.200.0120.03312.40
5.4.190.0040.03912.41
5.4.180.0080.03612.41
5.4.170.0060.03812.41
5.4.160.0040.04012.41
5.4.150.0110.04112.40
5.4.140.0100.04412.09
5.4.130.0080.03812.07
5.4.120.0140.02812.04
5.4.110.0050.03712.03
5.4.100.0080.03412.03
5.4.90.0090.03612.03
5.4.80.0070.03712.03
5.4.70.0050.03712.03
5.4.60.0100.03312.03
5.4.50.0060.03712.03
5.4.40.0090.03312.02
5.4.30.0060.03712.01
5.4.20.0090.03412.01
5.4.10.0070.03612.02
5.4.00.0050.03911.50
5.3.290.0040.04212.80
5.3.280.0080.03712.71
5.3.270.0090.03912.73
5.3.260.0090.03812.72
5.3.250.0080.03612.72
5.3.240.0060.03912.72
5.3.230.0090.03612.71
5.3.220.0080.03612.68
5.3.210.0070.04612.69
5.3.200.0060.03812.68
5.3.190.0070.03812.68
5.3.180.0080.03612.68
5.3.170.0040.04112.68
5.3.160.0070.03712.68
5.3.150.0120.03312.68
5.3.140.0060.03712.67
5.3.130.0060.04212.66
5.3.120.0070.03812.66
5.3.110.0060.04112.67
5.3.100.0060.03812.15
5.3.90.0050.03912.13
5.3.80.0070.03712.12
5.3.70.0070.03812.12
5.3.60.0070.03912.11
5.3.50.0050.04012.05
5.3.40.0060.03812.05
5.3.30.0090.03412.02
5.3.20.0060.03611.79
5.3.10.0080.03411.76
5.3.00.0070.03611.75
5.2.170.0050.0309.23
5.2.160.0050.0289.23
5.2.150.0060.0299.23
5.2.140.0060.0309.23
5.2.130.0040.0299.19
5.2.120.0070.0269.18
5.2.110.0030.0349.19
5.2.100.0090.0279.19
5.2.90.0060.0299.20
5.2.80.0040.0369.18
5.2.70.0070.0329.18
5.2.60.0050.0399.14
5.2.50.0050.0309.12
5.2.40.0040.0309.09
5.2.30.0070.0289.05
5.2.20.0080.0349.04
5.2.10.0060.0278.95
5.2.00.0040.0308.81
5.1.60.0070.0218.10
5.1.50.0040.0268.10
5.1.40.0050.0238.08
5.1.30.0020.0298.43
5.1.20.0050.0278.45
5.1.10.0040.0268.18
5.1.00.0060.0248.18
5.0.50.0010.0246.65
5.0.40.0010.0216.51
5.0.30.0020.0336.32
5.0.20.0050.0186.29
5.0.10.0010.0236.27
5.0.00.0020.0326.27
4.4.90.0050.0134.78
4.4.80.0050.0134.75
4.4.70.0030.0164.75
4.4.60.0050.0154.76
4.4.50.0020.0164.77
4.4.40.0040.0244.70
4.4.30.0030.0154.76
4.4.20.0030.0154.84
4.4.10.0040.0154.85
4.4.00.0060.0214.75
4.3.110.0020.0174.67
4.3.100.0030.0144.66
4.3.90.0030.0144.63
4.3.80.0040.0234.58
4.3.70.0040.0144.63
4.3.60.0030.0214.63
4.3.50.0040.0214.63
4.3.40.0040.0274.54
4.3.30.0020.0163.31
4.3.20.0020.0163.29
4.3.10.0020.0163.25
4.3.00.0000.02315.25

preferences:
45.5 ms | 401 KiB | 5 Q