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($name) { $length = strlen($name); if ($length < 2) { return strtolower($name); } $output = ''; // init stream $prev_val = '_'; $prev_upr = false; $char_val = $name[0]; $char_upr = ctype_upper($char_val); for ($i = 0; $i < $length; $i++) { // peek $next_val = $i+1 < $length ? $name[$i+1] : '_'; $next_upr = ctype_upper($next_val); if ($prev_val == '_') { if ($char_val == '_') { continue; } $output .= $char_val; } else if ($char_upr !== $prev_upr) { $output .= '_'.$char_val; } else if ($char_upr && !$next_upr && $next_val !== '_') { // && $prev_upr $output .= $char_val.'_'; $char_val = '_'; $char_upr = false; } else { $output .= $char_val; } // roll over $prev_val = $char_val; $prev_upr = $char_upr; $char_val = $next_val; $char_upr = $next_upr; } 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, 'split' => do_split($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.0140.00016.63
8.3.50.0130.00522.05
8.3.40.0150.00618.92
8.3.30.0090.00619.14
8.3.20.0040.00420.21
8.3.10.0040.00421.95
8.3.00.0040.00417.89
8.2.180.0090.01216.88
8.2.170.0160.00322.96
8.2.160.0100.00320.39
8.2.150.0070.00024.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0050.00321.01
8.2.110.0040.00420.16
8.2.100.0080.00318.03
8.2.90.0030.00517.88
8.2.80.0050.00318.73
8.2.70.0000.00817.63
8.2.60.0050.00317.80
8.2.50.0100.00018.07
8.2.40.0040.00418.16
8.2.30.0030.00518.34
8.2.20.0040.00417.83
8.2.10.0050.00218.19
8.2.00.0030.00617.94
8.1.280.0170.00325.92
8.1.270.0080.00022.32
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0070.00323.86
8.1.230.0060.00622.75
8.1.220.0000.00817.76
8.1.210.0090.00018.77
8.1.200.0040.00417.36
8.1.190.0030.00517.22
8.1.180.0080.00018.10
8.1.170.0090.00018.72
8.1.160.0040.00422.07
8.1.150.0030.00518.85
8.1.140.0040.00417.41
8.1.130.0030.00317.80
8.1.120.0000.00717.45
8.1.110.0040.00417.54
8.1.100.0050.00217.41
8.1.90.0070.00017.53
8.1.80.0080.00017.42
8.1.70.0030.00317.50
8.1.60.0000.00917.67
8.1.50.0040.00417.50
8.1.40.0000.00817.62
8.1.30.0030.00617.70
8.1.20.0040.00417.67
8.1.10.0080.00017.66
8.1.00.0030.00617.57
8.0.300.0000.00720.55
8.0.290.0040.00416.75
8.0.280.0000.00718.51
8.0.270.0080.00017.15
8.0.260.0030.00317.20
8.0.250.0030.00317.02
8.0.240.0070.00017.00
8.0.230.0030.00316.98
8.0.220.0070.00016.94
8.0.210.0000.00816.96
8.0.200.0030.00316.99
8.0.190.0030.00516.98
8.0.180.0000.00716.84
8.0.170.0040.00416.96
8.0.160.0070.00016.87
8.0.150.0000.00716.93
8.0.140.0030.00516.90
8.0.130.0030.00313.37
8.0.120.0040.00416.83
8.0.110.0040.00416.88
8.0.100.0030.00516.86
8.0.90.0040.00417.01
8.0.80.0100.01016.99
8.0.70.0040.00416.83
8.0.60.0040.00416.93
8.0.50.0000.00816.85
8.0.30.0090.01317.05
8.0.20.0090.01017.42
8.0.10.0000.00717.06
8.0.00.0090.01016.84
7.4.330.0000.00515.15
7.4.320.0000.00616.57
7.4.300.0030.00316.67
7.4.290.0040.00416.64
7.4.280.0040.00716.56
7.4.270.0040.00416.67
7.4.260.0030.00316.66
7.4.250.0020.00516.51
7.4.240.0020.00516.60
7.4.230.0000.00816.46
7.4.220.0060.01216.68
7.4.210.0110.00716.65
7.4.200.0070.00016.39
7.4.160.0110.00616.55
7.4.150.0140.00417.40
7.4.140.0060.01117.86
7.4.130.0070.01016.54
7.4.120.0120.00616.59
7.4.110.0090.01216.62
7.4.100.0100.00716.61
7.4.90.0100.00716.67
7.4.80.0170.00319.39
7.4.70.0090.00916.52
7.4.60.0070.01116.48
7.4.50.0050.00016.47
7.4.40.0120.00616.48
7.4.30.0130.00616.43
7.4.00.0030.01315.08
7.3.330.0000.00513.41
7.3.320.0030.00313.37
7.3.310.0000.00716.48
7.3.300.0000.00616.27
7.3.290.0060.00816.41
7.3.280.0100.00616.43
7.3.270.0100.00717.40
7.3.260.0040.01516.35
7.3.250.0130.00916.50
7.3.240.0080.00816.63
7.3.230.0070.01016.39
7.3.210.0060.01116.65
7.3.200.0080.00819.39
7.3.190.0150.00616.72
7.3.180.0110.00516.52
7.3.170.0110.00716.30
7.3.160.0140.00716.61
7.3.120.0030.01414.98
7.3.10.0000.01216.74
7.3.00.0030.00616.79
7.2.330.0080.00916.65
7.2.320.0060.01016.83
7.2.310.0080.00916.72
7.2.300.0120.00616.77
7.2.290.0100.00616.55
7.2.130.0060.00617.06
7.2.120.0070.00716.90
7.2.110.0080.00417.06
7.2.100.0070.00417.10
7.2.90.0070.00616.87
7.2.80.0090.00416.89
7.2.70.0060.00617.05
7.2.60.0060.00817.04
7.2.50.0080.00616.85
7.2.40.0080.00317.11
7.2.30.0040.00916.95
7.2.20.0080.00816.99
7.2.10.0070.00816.96
7.2.00.0100.00716.94
7.1.250.0070.00515.79
7.1.240.0030.01015.82
7.1.230.0050.00415.91
7.1.220.0000.01215.77
7.1.210.0060.00315.66
7.1.200.0060.00615.92
7.1.190.0060.00615.75
7.1.180.0090.00016.05
7.1.170.0100.00315.51
7.1.160.0040.00815.99
7.1.150.0070.00715.75
7.1.140.0060.00615.79
7.1.130.0070.00315.50
7.1.120.0040.00815.70
7.1.110.0040.00715.72
7.1.100.0030.01115.57
7.1.90.0080.00315.71
7.1.80.0040.00816.07
7.1.70.0040.00816.64
7.1.60.0030.00917.58
7.1.50.0070.00916.37
7.1.40.0060.00315.61
7.1.30.0080.00015.81
7.1.20.0060.00915.85
7.1.10.0000.01215.58
7.1.00.0070.03719.19
7.0.330.0000.00915.43
7.0.320.0060.00615.54
7.0.310.0000.01115.14
7.0.300.0040.00415.22
7.0.290.0060.00615.49
7.0.280.0030.00915.38
7.0.270.0060.00615.18
7.0.260.0040.00415.46
7.0.250.0060.01015.48
7.0.240.0000.01415.41
7.0.230.0030.00915.26
7.0.220.0030.01015.63
7.0.210.0060.00615.11
7.0.200.0030.00816.08
7.0.190.0060.00615.61
7.0.180.0030.00615.55
7.0.170.0070.00715.63
7.0.160.0070.00715.46
7.0.150.0060.00615.44
7.0.140.0070.03818.69
7.0.130.0070.00715.55
7.0.120.0000.01115.48
7.0.110.0040.01115.50
7.0.100.0110.00015.46
7.0.90.0030.00615.40
7.0.80.0040.01115.50
7.0.70.0070.00715.29
7.0.60.0020.04917.73
7.0.50.0050.04616.68
7.0.40.0000.02716.87
7.0.30.0210.02516.91
7.0.20.0150.03216.83
7.0.10.0050.02416.82
7.0.00.0030.04616.91
5.6.380.0050.00314.49
5.6.370.0040.00714.30
5.6.360.0040.00413.97
5.6.350.0030.01014.02
5.6.340.0060.00914.54
5.6.330.0030.00714.10
5.6.320.0130.00014.13
5.6.310.0110.00414.59
5.6.300.0060.00614.25
5.6.290.0060.00614.60
5.6.280.0050.03817.78
5.6.270.0090.00314.70
5.6.260.0040.00714.39
5.6.250.0060.00614.39
5.6.240.0030.00714.52
5.6.230.0110.00014.38
5.6.220.0080.01114.30
5.6.210.0050.02417.48
5.6.200.0070.04616.31
5.6.190.0090.04017.56
5.6.180.1860.02017.41
5.6.170.0230.02717.42
5.6.160.0050.03817.53
5.6.150.0070.03216.25
5.6.140.0080.03716.35
5.6.130.0040.04416.28
5.6.120.0050.04217.69
5.6.110.0100.04117.75
5.6.100.0080.03517.80
5.6.90.0070.03217.73
5.6.80.0030.03217.49
5.6.70.0070.00313.96
5.6.60.0060.00314.03
5.6.50.0080.00614.28
5.6.40.0070.00414.29
5.6.30.0070.00714.21
5.6.20.0100.00314.57
5.6.10.0040.00814.27
5.6.00.0030.00914.49
5.5.380.0040.00411.28
5.5.370.0000.00811.25
5.5.360.0030.01011.59
5.5.350.0050.03715.96
5.5.340.0130.03814.58
5.5.330.0070.02215.82
5.5.320.0150.04415.91
5.5.310.0110.02315.89
5.5.300.0120.03714.80
5.5.290.0020.04414.63
5.5.280.0050.03415.95
5.5.270.0080.02316.08
5.5.260.0040.04816.19
5.5.250.0020.04115.89
5.5.240.1920.02215.76
5.5.230.0000.00911.41
5.5.220.0030.00311.00
5.5.210.0000.01111.13
5.5.200.0000.00811.17
5.5.190.0040.00411.38
5.5.180.0000.00811.24
5.5.170.0060.00611.27
5.5.160.0060.00311.22
5.5.150.0030.00311.47
5.5.140.0080.00011.10
5.5.130.0100.00011.00
5.5.120.0000.01111.33
5.5.110.0040.00711.35
5.5.100.0030.00611.00
5.5.90.0000.00811.07
5.5.80.0040.00711.29
5.5.70.0070.00311.05
5.5.60.0060.00311.21
5.5.50.0070.00411.31
5.5.40.0040.00411.32
5.5.30.0050.00011.33
5.5.20.0070.00311.39
5.5.10.0030.00311.40
5.5.00.0060.00311.36
5.4.450.0320.03715.29
5.4.440.0180.02715.35
5.4.430.0130.02715.41
5.4.420.0140.02415.45
5.4.410.0040.03015.01
5.4.400.0230.02814.91
5.4.390.0230.03014.89
5.4.380.0100.03014.77
5.4.370.0040.02214.95
5.4.360.0030.02214.87
5.4.350.0050.02711.74
5.4.340.0080.02211.52
5.4.330.0000.00511.23
5.4.320.0040.02311.85
5.4.310.0060.02211.79
5.4.300.0050.02111.95
5.4.290.0090.02211.87
5.4.280.0040.02111.84
5.4.270.0080.02011.74
5.4.260.0070.01911.83
5.4.250.0090.01811.87
5.4.240.0050.02111.80
5.4.230.0030.02311.73
5.4.220.0040.02111.84
5.4.210.0040.02311.81
5.4.200.0110.02011.70
5.4.190.0020.02511.70
5.4.180.0040.02311.70
5.4.170.0050.01911.70
5.4.160.0050.02311.70
5.4.150.0050.02011.89
5.4.140.0040.02211.57
5.4.130.0020.02211.54
5.4.120.0060.01911.53
5.4.110.0050.01911.54
5.4.100.0050.02111.60
5.4.90.0020.02311.62
5.4.80.0050.02011.51
5.4.70.0070.01811.56
5.4.60.0020.02211.68
5.4.50.0060.01811.67
5.4.40.0040.02111.56
5.4.30.0050.02011.61
5.4.20.0070.02111.51
5.4.10.0060.01911.69
5.4.00.0030.02211.40
5.3.290.0040.02711.90
5.3.280.0060.02111.86
5.3.270.0070.02211.86
5.3.260.0050.02111.86
5.3.250.0070.02511.86
5.3.240.0030.02311.86
5.3.230.0060.02311.86
5.3.220.0060.02211.84
5.3.210.0040.02411.84
5.3.200.0040.02111.84
5.3.190.0050.02411.84
5.3.180.0080.01911.84
5.3.170.0040.02511.84
5.3.160.0080.02311.84
5.3.150.0100.02011.84
5.3.140.0040.02911.83
5.3.130.0070.02011.83
5.3.120.0040.02411.83
5.3.110.0060.02111.83
5.3.100.0050.02211.57
5.3.90.0080.01911.56
5.3.80.0050.02011.55
5.3.70.0090.02211.55
5.3.60.0040.02111.54
5.3.50.0050.02311.52
5.3.40.0040.02111.52
5.3.30.0050.02011.50
5.3.20.0050.02011.39
5.3.10.0050.02011.37
5.3.00.0050.01911.37
5.2.170.0020.02010.12
5.2.160.0020.01710.12
5.2.150.0040.01810.12
5.2.140.0020.02110.12
5.2.130.0040.02010.10
5.2.120.0060.01610.10
5.2.110.0040.01710.10
5.2.100.0040.01710.09
5.2.90.0050.01410.09
5.2.80.0040.01710.09
5.2.70.0040.01910.09
5.2.60.0050.01610.08
5.2.50.0040.01610.06
5.2.40.0020.01910.05
5.2.30.0050.01810.03
5.2.20.0060.01610.03
5.2.10.0040.0229.98
5.2.00.0050.0169.91
5.1.60.0050.0139.55
5.1.50.0030.0159.55
5.1.40.0050.0139.54
5.1.30.0020.0169.72
5.1.20.0050.0169.73
5.1.10.0040.0149.59
5.1.00.0050.0209.59
5.0.50.0040.0128.83
5.0.40.0030.0128.76
5.0.30.0050.0168.67
5.0.20.0030.0118.65
5.0.10.0050.0098.64
5.0.00.0020.0178.64
4.4.90.0020.0107.89
4.4.80.0020.0107.88
4.4.70.0020.0107.88
4.4.60.0020.0097.88
4.4.50.0020.0097.89
4.4.40.0020.0157.86
4.4.30.0020.0117.88
4.4.20.0020.0127.93
4.4.10.0020.0097.93
4.4.00.0050.0157.88
4.3.110.0050.0097.84
4.3.100.0040.0097.83
4.3.90.0050.0097.82
4.3.80.0030.0147.79
4.3.70.0030.0097.82
4.3.60.0010.0107.81
4.3.50.0040.0107.81
4.3.40.0030.0127.77
4.3.30.0010.0117.17
4.3.20.0010.0117.15
4.3.10.0010.0127.14
4.3.00.0090.0129.11

preferences:
49.23 ms | 401 KiB | 5 Q