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)
5.4.310.0050.04012.52
5.4.300.0090.03812.52
5.4.290.0140.03312.52
5.4.280.0110.03512.42
5.4.270.0050.04112.42
5.4.260.0110.04612.41
5.4.250.0040.04212.41
5.4.240.0090.03712.42
5.4.230.0060.04012.41
5.4.220.0040.03912.41
5.4.210.0080.04212.41
5.4.200.0100.04112.41
5.4.190.0060.04012.40
5.4.180.0080.04012.40
5.4.170.0060.03612.41
5.4.160.0040.03812.41
5.4.150.0070.03612.40
5.4.140.0050.03912.09
5.4.130.0030.04012.07
5.4.120.0040.03912.04
5.4.110.0060.03712.04
5.4.100.0050.04312.04
5.4.90.0090.04512.04
5.4.80.0040.04112.04
5.4.70.0060.03612.03
5.4.60.0070.03612.03
5.4.50.0060.03712.03
5.4.40.0070.03612.02
5.4.30.0090.03512.01
5.4.20.0060.04312.01
5.4.10.0070.04812.01
5.4.00.0080.04111.50
5.3.280.0070.04212.71
5.3.270.0140.04612.72
5.3.260.0080.04912.71
5.3.250.0110.04812.72
5.3.240.0150.04312.72
5.3.230.0090.04812.71
5.3.220.0060.05212.68
5.3.210.0090.05212.68
5.3.200.0090.04812.68
5.3.190.0070.04812.68
5.3.180.0100.04712.67
5.3.170.0120.04612.67
5.3.160.0110.04612.67
5.3.150.0070.05012.67
5.3.140.0080.04912.66
5.3.130.0100.04912.65
5.3.120.0080.04312.66
5.3.110.0070.04312.65
5.3.100.0120.04412.13
5.3.90.0090.04312.11
5.3.80.0090.03312.11
5.3.70.0070.03712.10
5.3.60.0020.04112.09
5.3.50.0080.03512.04
5.3.40.0040.03912.04
5.3.30.0050.04412.00
5.3.20.0040.04411.78
5.3.10.0090.03511.75
5.3.00.0080.03911.73
5.2.170.0050.0309.23
5.2.160.0030.0329.23
5.2.150.0050.0369.23
5.2.140.0050.0349.23
5.2.130.0050.0319.18
5.2.120.0060.0289.18
5.2.110.0070.0279.19
5.2.100.0050.0289.18
5.2.90.0040.0319.19
5.2.80.0030.0329.18
5.2.70.0080.0299.18
5.2.60.0090.0279.14
5.2.50.0050.0309.11
5.2.40.0060.0279.09
5.2.30.0040.0309.05
5.2.20.0070.0279.05
5.2.10.0040.0298.95
5.2.00.0050.0298.82
5.1.60.0060.0238.10
5.1.50.0040.0258.10
5.1.40.0100.0208.08
5.1.30.0060.0308.42
5.1.20.0080.0238.45
5.1.10.0030.0298.18
5.1.00.0040.0268.17
5.0.50.0020.0226.65
5.0.40.0030.0206.51
5.0.30.0020.0326.32
5.0.20.0050.0256.29
5.0.10.0030.0276.27
5.0.00.0040.0336.26
4.4.90.0010.0174.78
4.4.80.0000.0204.76
4.4.70.0040.0154.75
4.4.60.0030.0164.75
4.4.50.0030.0154.77
4.4.40.0040.0244.70
4.4.30.0030.0184.76
4.4.20.0040.0184.84
4.4.10.0010.0234.85
4.4.00.0020.0284.76
4.3.110.0040.0164.66
4.3.100.0040.0174.66
4.3.90.0050.0134.63
4.3.80.0050.0254.58
4.3.70.0030.0184.63
4.3.60.0030.0164.63
4.3.50.0000.0204.63
4.3.40.0050.0284.54
4.3.30.0030.0163.31
4.3.20.0030.0173.29
4.3.10.0010.0173.25
4.3.00.0100.02015.25

preferences:
140.4 ms | 1394 KiB | 7 Q