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($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.70.0030.01718.43
8.3.60.0090.00918.31
8.3.50.0150.00421.93
8.3.40.0100.00718.71
8.3.30.0120.00319.09
8.3.20.0040.00420.20
8.3.10.0000.00821.77
8.3.00.0050.00318.04
8.2.180.0090.00616.88
8.2.170.0040.01122.96
8.2.160.0090.00620.45
8.2.150.0070.00024.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0080.00021.08
8.2.110.0090.00021.12
8.2.100.0060.00617.84
8.2.90.0040.00419.40
8.2.80.0040.00417.97
8.2.70.0030.00617.63
8.2.60.0030.00518.03
8.2.50.0090.00018.09
8.2.40.0000.00818.16
8.2.30.0000.00818.33
8.2.20.0040.00417.88
8.2.10.0000.00818.10
8.2.00.0000.00817.62
8.1.280.0150.00025.92
8.1.270.0140.00023.99
8.1.260.0040.00426.35
8.1.250.0060.00328.09
8.1.240.0040.00422.14
8.1.230.0040.00718.95
8.1.220.0040.00417.79
8.1.210.0060.00318.77
8.1.200.0030.00717.36
8.1.190.0040.00417.35
8.1.180.0000.00818.10
8.1.170.0040.00418.70
8.1.160.0000.00722.09
8.1.150.0000.00718.93
8.1.140.0060.00317.49
8.1.130.0000.00717.88
8.1.120.0070.00017.54
8.1.110.0040.00417.53
8.1.100.0040.00417.39
8.1.90.0000.00717.55
8.1.80.0030.00317.50
8.1.70.0040.00417.50
8.1.60.0000.00717.67
8.1.50.0030.00517.63
8.1.40.0000.00817.59
8.1.30.0030.00617.72
8.1.20.0050.00317.68
8.1.10.0080.00017.51
8.1.00.0000.00817.57
8.0.300.0050.00518.77
8.0.290.0040.00416.75
8.0.280.0040.00418.42
8.0.270.0000.00817.30
8.0.260.0030.00317.16
8.0.250.0070.00016.98
8.0.240.0000.00716.84
8.0.230.0000.00716.91
8.0.220.0030.00516.79
8.0.210.0000.00716.89
8.0.200.0000.00616.88
8.0.190.0020.00516.91
8.0.180.0000.00716.98
8.0.170.0060.00316.86
8.0.160.0070.00016.91
8.0.150.0030.00616.89
8.0.140.0080.00316.80
8.0.130.0000.00513.37
8.0.120.0040.00416.94
8.0.110.0040.00416.95
8.0.100.0040.00416.93
8.0.90.0070.00016.75
8.0.80.0120.00917.00
8.0.70.0080.00017.07
8.0.60.0020.00516.84
8.0.50.0030.00516.90
8.0.30.0130.00817.26
8.0.20.0110.01117.40
8.0.10.0000.00716.94
8.0.00.0070.01216.83
7.4.330.0050.00015.00
7.4.320.0000.00716.67
7.4.300.0000.00716.54
7.4.290.0070.00016.67
7.4.280.0040.00416.66
7.4.270.0040.00416.61
7.4.260.0030.00616.64
7.4.250.0000.00716.54
7.4.240.0040.00416.67
7.4.230.0040.00416.36
7.4.220.0100.01016.48
7.4.210.0100.00316.48
7.4.200.0050.00316.39
7.4.160.0030.01216.43
7.4.150.0120.00617.40
7.4.140.0060.01417.86
7.4.130.0130.00516.57
7.4.120.0110.00616.55
7.4.110.0070.01316.54
7.4.100.0120.00316.51
7.4.90.0030.01516.57
7.4.80.0030.01519.39
7.4.70.0060.01116.57
7.4.60.0090.00916.70
7.4.50.0060.00016.41
7.4.40.0100.01016.63
7.4.30.0130.00316.41
7.4.00.0090.00714.92
7.3.330.0000.00613.26
7.3.320.0000.00513.24
7.3.310.0000.00716.39
7.3.300.0030.00316.38
7.3.290.0050.01016.41
7.3.280.0080.00916.37
7.3.270.0140.00417.40
7.3.260.0070.01016.43
7.3.250.0060.01316.53
7.3.240.0060.01616.42
7.3.230.0080.00816.59
7.3.210.0090.00916.34
7.3.200.0060.00919.39
7.3.190.0120.00616.60
7.3.180.0070.01016.55
7.3.170.0030.01416.52
7.3.160.0160.00016.40
7.3.120.0060.00915.01
7.3.110.0030.01415.00
7.3.100.0000.01614.80
7.3.90.0030.01114.71
7.3.80.0060.00914.85
7.3.70.0100.00014.82
7.3.60.0110.00414.44
7.3.50.0050.00514.70
7.3.40.0040.00914.94
7.3.30.0110.00015.00
7.3.20.0030.00916.73
7.3.10.0040.01116.71
7.3.00.0100.00716.51
7.2.330.0150.00416.76
7.2.320.0140.00616.65
7.2.310.0030.01316.72
7.2.300.0100.00716.76
7.2.290.0040.01116.69
7.2.250.0120.00314.98
7.2.240.0030.01715.13
7.2.230.0120.00615.19
7.2.220.0090.00914.95
7.2.210.0030.01014.63
7.2.200.0060.00615.03
7.2.190.0030.01215.11
7.2.180.0030.00915.11
7.2.170.0070.00715.04
7.1.330.0090.00315.79
7.1.320.0080.00415.75
7.1.310.0090.00615.89
7.1.300.0000.01615.60
7.1.290.0040.01216.02
7.1.280.0100.00615.85
7.1.270.0060.00315.77
7.1.260.0030.01015.96
7.1.200.0070.00315.59
7.1.100.0040.01117.86
7.1.70.0130.00016.91
7.1.60.0110.01419.25
7.1.50.0040.01116.95
7.1.00.0100.07022.54
7.0.200.0040.00416.75
7.0.140.0070.07022.21
7.0.60.0030.08019.90
7.0.50.0130.08017.99
7.0.40.0030.04320.27
7.0.30.0300.07720.23
7.0.20.0130.05720.09
7.0.10.0130.09020.15
7.0.00.0070.07320.07
5.6.210.0030.04020.79
5.6.200.0030.06718.28
5.6.190.0070.05020.61
5.6.180.0200.04320.48
5.6.170.0270.05020.58
5.6.160.0100.08020.46
5.6.150.0200.06318.21
5.6.140.0030.08318.28
5.6.130.0070.08018.19
5.6.120.0070.04021.04
5.6.110.0000.04321.13
5.6.100.0070.06321.11
5.6.90.0030.04320.99
5.6.80.0130.07720.49
5.5.350.4170.04020.32
5.5.340.0030.07317.94
5.5.330.0070.05320.40
5.5.320.3570.04720.52
5.5.310.0130.05320.50
5.5.300.0070.07717.96
5.5.290.0130.07318.05
5.5.280.0070.09020.82
5.5.270.0170.07720.78
5.5.260.0130.08320.64
5.5.250.0100.08320.70
5.5.240.0070.07020.18
5.4.450.0270.04319.59
5.4.440.0370.04019.31
5.4.430.0100.05019.55
5.4.420.0730.03719.57
5.4.410.0500.04719.27
5.4.400.0400.04019.32
5.4.390.0530.04318.98
5.4.380.0170.05318.78
5.4.370.0100.05318.61
5.4.360.0300.06018.69
5.4.350.0130.05718.62
5.4.340.0130.05318.66
5.4.320.0090.05112.52
5.4.310.0050.03912.52
5.4.300.0100.03412.52
5.4.290.0080.03712.51
5.4.280.0080.03412.41
5.4.270.0060.03912.41
5.4.260.0100.03512.41
5.4.250.0090.03712.41
5.4.240.0080.03612.42
5.4.230.0070.03912.41
5.4.220.0080.03612.41
5.4.210.0090.03412.41
5.4.200.0070.03812.41
5.4.190.0080.04612.40
5.4.180.0090.03912.41
5.4.170.0080.03512.41
5.4.160.0070.03612.41
5.4.150.0060.03812.41
5.4.140.0050.04012.09
5.4.130.0080.03512.07
5.4.120.0050.03712.03
5.4.110.0070.03612.03
5.4.100.0080.03512.04
5.4.90.0070.03812.03
5.4.80.0080.03712.03
5.4.70.0070.03812.03
5.4.60.0100.03212.03
5.4.50.0080.03512.03
5.4.40.0100.03212.02
5.4.30.0080.03612.01
5.4.20.0080.03512.02
5.4.10.0080.03812.01
5.4.00.0080.04011.50
5.3.290.0090.05312.80
5.3.280.0060.04112.71
5.3.270.0040.04612.72
5.3.260.0090.03812.72
5.3.250.0130.03212.72
5.3.240.0070.03812.72
5.3.230.0070.03812.71
5.3.220.0060.03812.68
5.3.210.0060.04012.68
5.3.200.0080.03612.68
5.3.190.0040.04112.68
5.3.180.0060.03712.68
5.3.170.0100.03412.68
5.3.160.0080.03612.68
5.3.150.0070.03712.68
5.3.140.0100.03412.66
5.3.130.0070.03912.67
5.3.120.0090.03712.67
5.3.110.0090.03712.66
5.3.100.0080.03712.15
5.3.90.0090.04312.13
5.3.80.0100.04312.12
5.3.70.0090.03412.13
5.3.60.0100.03312.11
5.3.50.0100.04012.06
5.3.40.0110.03912.05
5.3.30.0070.03612.02
5.3.20.0080.03511.80
5.3.10.0070.03511.76
5.3.00.0060.03811.75
5.2.170.0050.0319.23
5.2.160.0050.0309.23
5.2.150.0040.0319.23
5.2.140.0040.0319.23
5.2.130.0060.0279.19
5.2.120.0050.0279.19
5.2.110.0070.0269.19
5.2.100.0050.0289.19
5.2.90.0040.0359.18
5.2.80.0090.0389.18
5.2.70.0060.0359.18
5.2.60.0030.0339.15
5.2.50.0030.0329.12
5.2.40.0080.0259.09
5.2.30.0040.0309.06
5.2.20.0030.0309.05
5.2.10.0050.0278.95
5.2.00.0030.0308.81
5.1.60.0020.0288.11
5.1.50.0040.0288.09
5.1.40.0030.0278.08
5.1.30.0080.0278.42
5.1.20.0070.0308.45
5.1.10.0020.0288.18
5.1.00.0010.0288.17
5.0.50.0030.0216.65
5.0.40.0030.0206.51
5.0.30.0060.0326.32
5.0.20.0010.0216.29
5.0.10.0040.0196.27
5.0.00.0020.0326.26
4.4.90.0030.0214.77
4.4.80.0040.0154.75
4.4.70.0020.0224.75
4.4.60.0030.0184.76
4.4.50.0040.0214.77
4.4.40.0020.0344.71
4.4.30.0030.0184.76
4.4.20.0050.0144.84
4.4.10.0080.0104.85
4.4.00.0030.0264.75
4.3.110.0040.0154.67
4.3.100.0000.0184.66
4.3.90.0040.0144.63
4.3.80.0070.0214.58
4.3.70.0030.0144.63
4.3.60.0030.0164.63
4.3.50.0030.0174.63
4.3.40.0020.0294.54
4.3.30.0030.0173.31
4.3.20.0020.0163.29
4.3.10.0040.0143.25
4.3.00.0000.02015.25

preferences:
38.22 ms | 401 KiB | 5 Q