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.0470.05319.09
5.4.300.0430.07018.87
5.4.290.0470.03719.22
5.4.280.0530.04019.31
5.4.270.0500.03318.85
5.4.260.0430.04719.15
5.4.250.0430.04719.30
5.4.240.0530.04018.94
5.4.230.0430.05319.08
5.4.220.0500.05719.24
5.4.210.0570.06319.08
5.4.200.0400.04718.97
5.4.190.0400.04319.21
5.4.180.0500.03719.07
5.4.170.0500.05319.05
5.4.160.0430.05318.85
5.4.150.0630.05318.86
5.4.140.0430.06316.46
5.4.130.0530.03016.39
5.4.120.0270.04316.45
5.4.110.0500.06016.50
5.4.100.0430.05016.51
5.4.90.0430.06316.56
5.4.80.0600.04016.59
5.4.70.0430.05316.49
5.4.60.0400.03716.38
5.4.50.0530.06716.43
5.4.40.0370.04716.51
5.4.30.0500.06316.55
5.4.20.0370.03716.51
5.4.10.0570.05316.53
5.4.00.0500.06015.95
5.3.280.0370.04314.77
5.3.270.0570.05014.64
5.3.260.0500.04314.52
5.3.250.0430.03014.83
5.3.240.0500.06714.59
5.3.230.0470.06014.60
5.3.220.0470.03014.48
5.3.210.0500.05014.61
5.3.200.0370.04014.69
5.3.190.0600.05314.58
5.3.180.0530.06314.55
5.3.170.0430.04714.72
5.3.160.0500.05714.62
5.3.150.0430.06014.57
5.3.140.0500.05714.57
5.3.130.0500.06014.61
5.3.120.0530.05714.46
5.3.110.0500.06014.52
5.3.100.0370.06314.13
5.3.90.0500.04714.11
5.3.80.0500.06014.07
5.3.70.0500.03713.95
5.3.60.0470.06314.09
5.3.50.0470.06313.89
5.3.40.0470.06313.89
5.3.30.0470.06313.84
5.3.20.0470.06313.76
5.3.10.0530.03313.58
5.3.00.0470.06313.56
5.2.170.0400.04311.16
5.2.160.0400.04711.36
5.2.150.0500.04711.27
5.2.140.0400.04011.21
5.2.130.0430.05311.12
5.2.120.0370.04011.02
5.2.110.0370.03311.15
5.2.100.0430.05311.33
5.2.90.0500.03711.33
5.2.80.0330.03311.08
5.2.70.0470.03711.03
5.2.60.0400.05010.97
5.2.50.0400.05710.93
5.2.40.0370.05011.07
5.2.30.0370.03710.98
5.2.20.0300.03710.93
5.2.10.0330.04010.95
5.2.00.0270.04010.69
5.1.60.0370.02310.08
5.1.50.0330.0279.94
5.1.40.0270.0439.97
5.1.30.0300.04710.39
5.1.20.0470.04010.41
5.1.10.0370.04710.13
5.1.00.0370.04710.16
5.0.50.0230.0379.52
5.0.40.0130.0279.52
5.0.30.0070.0379.52
5.0.20.0170.0339.52
5.0.10.0170.0379.52
5.0.00.0170.0579.52
4.4.90.0200.0339.52
4.4.80.0130.0339.52
4.4.70.0200.0309.52
4.4.60.0170.0339.52
4.4.50.0130.0339.52
4.4.40.0170.0339.52
4.4.30.0170.0309.52
4.4.20.0130.0279.52
4.4.10.0200.0209.52
4.4.00.0230.0279.52
4.3.110.0170.0139.52
4.3.100.0100.0379.52
4.3.90.0200.0279.52
4.3.80.0170.0379.52
4.3.70.0170.0279.52
4.3.60.0230.0409.52
4.3.50.0170.0339.52
4.3.40.0070.0309.52
4.3.30.0070.0139.52
4.3.20.0130.0339.52
4.3.10.0130.0309.52
4.3.00.0070.0309.52

preferences:
159.21 ms | 1394 KiB | 7 Q