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)
5.4.310.0040.04112.53
5.4.300.0050.03912.54
5.4.290.0050.03912.54
5.4.280.0060.03612.43
5.4.270.0040.03912.43
5.4.260.0060.03712.43
5.4.250.0070.03712.43
5.4.240.0050.03712.43
5.4.230.0050.03912.42
5.4.220.0030.03812.42
5.4.210.0050.03612.42
5.4.200.0070.03612.42
5.4.190.0050.03712.42
5.4.180.0070.03712.42
5.4.170.0050.03712.42
5.4.160.0050.03812.42
5.4.150.0070.03712.41
5.4.140.0040.04012.11
5.4.130.0080.03612.09
5.4.120.0100.03212.05
5.4.110.0030.03912.05
5.4.100.0040.03912.05
5.4.90.0070.03612.05
5.4.80.0060.03712.05
5.4.70.0090.03212.05
5.4.60.0050.03612.04
5.4.50.0070.03512.05
5.4.40.0070.03412.04
5.4.30.0080.03312.03
5.4.20.0050.03612.03
5.4.10.0040.03712.03
5.4.00.0050.03611.52
5.3.280.0040.03912.71
5.3.270.0070.03812.72
5.3.260.0040.04212.72
5.3.250.0070.03612.72
5.3.240.0060.03812.72
5.3.230.0070.03612.71
5.3.220.0060.03712.68
5.3.210.0040.04012.68
5.3.200.0060.03712.68
5.3.190.0050.03912.68
5.3.180.0040.04112.68
5.3.170.0100.03812.67
5.3.160.0060.03612.68
5.3.150.0060.03812.68
5.3.140.0070.03512.67
5.3.130.0080.03612.66
5.3.120.0050.04012.66
5.3.110.0080.04212.66
5.3.100.0060.03812.15
5.3.90.0050.03712.13
5.3.80.0090.03412.12
5.3.70.0030.03912.12
5.3.60.0050.03712.11
5.3.50.0100.03312.05
5.3.40.0070.03612.05
5.3.30.0060.03612.01
5.3.20.0060.03611.79
5.3.10.0080.04111.76
5.3.00.0090.04411.75
5.2.170.0050.0309.23
5.2.160.0040.0319.23
5.2.150.0050.0319.24
5.2.140.0060.0299.23
5.2.130.0070.0399.19
5.2.120.0050.0329.19
5.2.110.0030.0319.19
5.2.100.0070.0269.18
5.2.90.0040.0299.18
5.2.80.0040.0319.18
5.2.70.0070.0319.18
5.2.60.0060.0309.14
5.2.50.0030.0329.11
5.2.40.0030.0319.09
5.2.30.0080.0279.06
5.2.20.0050.0319.05
5.2.10.0050.0418.95
5.2.00.0070.0388.81
5.1.60.0020.0278.10
5.1.50.0020.0278.09
5.1.40.0070.0228.08
5.1.30.0050.0268.43
5.1.20.0050.0278.45
5.1.10.0090.0288.18
5.1.00.0060.0248.17
5.0.50.0030.0226.66
5.0.40.0020.0226.52
5.0.30.0020.0326.32
5.0.20.0010.0226.29
5.0.10.0010.0236.27
5.0.00.0070.0296.26
4.4.90.0050.0204.78
4.4.80.0050.0164.76
4.4.70.0030.0184.76
4.4.60.0020.0194.75
4.4.50.0040.0174.77
4.4.40.0020.0304.71
4.4.30.0030.0174.75
4.4.20.0030.0174.84
4.4.10.0030.0164.85
4.4.00.0060.0214.76
4.3.110.0040.0144.67
4.3.100.0040.0154.66
4.3.90.0030.0144.63
4.3.80.0050.0254.58
4.3.70.0030.0164.63
4.3.60.0030.0174.63
4.3.50.0050.0164.63
4.3.40.0040.0234.54
4.3.30.0020.0163.31
4.3.20.0000.0183.29
4.3.10.0020.0203.25
4.3.00.0130.01015.25

preferences:
140.26 ms | 1394 KiB | 7 Q