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() use ($in, &$pos, $len) { if ($pos+1 >= $len) { return null; } return $in[$pos+1]; }; $next = function() use ($peek, &$pos) { $c = $peek(); if ($c === null) { return null; } $pos++; return $c; }; $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 () use (&$out, $next, $peek) { for ($c = $next(); $c !== null; $c = $next()) { $out .= $c; } 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.60.0120.00318.45
8.3.50.0130.01122.05
8.3.40.0110.00418.96
8.3.30.0210.00019.21
8.3.20.0120.00620.16
8.3.10.0040.00421.69
8.3.00.0090.00018.02
8.2.180.0180.00016.32
8.2.170.0170.00322.96
8.2.160.0170.00320.51
8.2.150.0060.00324.18
8.2.140.0060.00324.66
8.2.130.0080.00026.16
8.2.120.0110.00721.04
8.2.110.0060.00322.13
8.2.100.0070.00418.16
8.2.90.0050.00319.07
8.2.80.0080.00017.97
8.2.70.0060.00317.75
8.2.60.0030.00617.93
8.2.50.0040.00418.07
8.2.40.0030.00618.16
8.2.30.0040.00418.34
8.2.20.0080.00017.90
8.2.10.0070.00018.17
8.2.00.0040.00417.84
8.1.280.0140.00025.92
8.1.270.0050.00323.97
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0030.00622.09
8.1.230.0050.00519.16
8.1.220.0040.00417.74
8.1.210.0060.00318.77
8.1.200.0030.00617.50
8.1.190.0040.00417.25
8.1.180.0000.00818.10
8.1.170.0000.00818.49
8.1.160.0000.00721.96
8.1.150.0000.00718.91
8.1.140.0030.00517.55
8.1.130.0030.00317.92
8.1.120.0030.00417.42
8.1.110.0040.00417.42
8.1.100.0040.00417.54
8.1.90.0040.00417.45
8.1.80.0040.00417.39
8.1.70.0030.00317.44
8.1.60.0050.00317.51
8.1.50.0050.00517.58
8.1.40.0040.00417.48
8.1.30.0000.00917.59
8.1.20.0040.00417.67
8.1.10.0040.00417.62
8.1.00.0050.00317.51
8.0.300.0050.00318.77
8.0.290.0070.00016.75
8.0.280.0030.00318.38
8.0.270.0040.00417.27
8.0.260.0000.00717.27
8.0.250.0030.00317.01
8.0.240.0000.00717.02
8.0.230.0030.00316.91
8.0.220.0000.00716.93
8.0.210.0070.00017.03
8.0.200.0030.00317.03
8.0.190.0080.00016.92
8.0.180.0030.00316.91
8.0.170.0080.00016.88
8.0.160.0040.00416.97
8.0.150.0030.00616.89
8.0.140.0030.00616.94
8.0.130.0060.00313.35
8.0.120.0040.00416.90
8.0.110.0030.00516.95
8.0.100.0070.00017.05
8.0.90.0000.00816.88
8.0.80.0100.01316.93
8.0.70.0000.00816.96
8.0.60.0040.00416.87
8.0.50.0080.00016.84
8.0.30.0100.01117.14
8.0.20.0090.01317.40
8.0.10.0030.00517.11
8.0.00.0090.00916.87
7.4.330.0030.00315.13
7.4.320.0030.00316.57
7.4.300.0060.00016.59
7.4.290.0040.00416.52
7.4.280.0050.00316.65
7.4.270.0080.00016.64
7.4.260.0070.00316.63
7.4.250.0050.00216.46
7.4.240.0020.00516.54
7.4.230.0000.00716.68
7.4.220.0040.01416.55
7.4.210.0070.01116.67
7.4.200.0000.00716.36
7.4.160.0090.01216.51
7.4.150.0150.00917.40
7.4.140.0060.01117.86
7.4.130.0080.01316.48
7.4.120.0110.00716.44
7.4.110.0040.01716.55
7.4.100.0090.00916.61
7.4.90.0110.00716.61
7.4.80.0130.01019.39
7.4.70.0080.01416.59
7.4.60.0100.00716.45
7.4.50.0000.00516.61
7.4.40.0110.00516.62
7.4.30.0080.00816.29
7.4.00.0050.00514.79
7.3.330.0000.00613.38
7.3.320.0000.00513.34
7.3.310.0080.00016.28
7.3.300.0060.00016.38
7.3.290.0080.00816.38
7.3.280.0100.00616.38
7.3.270.0140.00317.40
7.3.260.0150.00716.70
7.3.250.0100.01116.31
7.3.240.0140.00416.45
7.3.230.0060.01016.54
7.3.210.0090.00916.69
7.3.200.0060.01119.39
7.3.190.0160.00616.49
7.3.180.0100.00716.30
7.3.170.0160.01016.39
7.3.160.0110.00716.40
7.3.120.0030.00714.84
7.2.330.0100.00716.97
7.2.320.0120.00616.91
7.2.310.0120.00616.65
7.2.300.0090.01316.89
7.2.290.0130.00916.91
7.2.60.0000.00817.01
7.2.00.0030.01019.67
7.1.200.0080.00315.91
7.1.100.0030.01018.08
7.1.70.0000.00717.38
7.1.60.0060.01819.25
7.1.50.0140.01116.69
7.1.00.0170.08022.57
7.0.200.0060.01216.86
7.0.140.0070.07021.91
7.0.60.0100.05020.05
7.0.50.0100.05717.84
7.0.40.0100.04020.23
7.0.30.0230.08320.26
7.0.20.0300.06320.28
7.0.10.0030.04720.24
7.0.00.0070.08720.23
5.6.280.0070.07321.04
5.6.210.0030.07020.59
5.6.200.0070.04318.29
5.6.190.0030.04320.58
5.6.180.0300.06020.50
5.6.170.0230.08020.50
5.6.160.0100.03720.58
5.6.150.0030.04018.18
5.6.140.0030.08018.14
5.6.130.0030.04318.24
5.6.120.0030.05021.02
5.6.110.0100.08020.99
5.6.100.0100.05321.05
5.6.90.0030.06721.14
5.6.80.0100.06720.43
5.5.350.4300.04020.49
5.5.340.0130.06018.02
5.5.330.0130.07320.43
5.5.320.3100.05320.31
5.5.310.0300.06020.38
5.5.300.0100.05717.98
5.5.290.0030.08717.99
5.5.280.0170.07020.77
5.5.270.0070.08020.79
5.5.260.0170.07320.89
5.5.250.0230.05320.73
5.5.240.0070.07020.21
5.4.450.0200.04719.48
5.4.440.0270.05019.51
5.4.430.0870.05019.57
5.4.420.0600.04019.31
5.4.410.0200.04319.20
5.4.400.0530.03019.16
5.4.390.0230.05719.25
5.4.380.0830.06018.48
5.4.370.0700.07018.51
5.4.360.0600.06318.76
5.4.350.1200.05018.73
5.4.340.0830.05018.52
5.4.320.0060.03612.53
5.4.310.0040.04312.52
5.4.300.0060.04412.53
5.4.290.0070.03912.53
5.4.280.0080.03512.43
5.4.270.0040.04012.42
5.4.260.0070.04012.42
5.4.250.0110.03412.42
5.4.240.0060.03812.42
5.4.230.0060.03912.41
5.4.220.0070.03712.42
5.4.210.0080.03612.42
5.4.200.0100.03612.42
5.4.190.0050.03812.41
5.4.180.0090.03712.41
5.4.170.0060.03812.42
5.4.160.0080.03512.42
5.4.150.0070.03712.42
5.4.140.0030.04212.10
5.4.130.0090.03812.08
5.4.120.0080.03512.04
5.4.110.0090.04212.04
5.4.100.0110.04612.04
5.4.90.0090.04112.04
5.4.80.0090.03812.04
5.4.70.0050.03812.04
5.4.60.0090.03412.04
5.4.50.0100.03312.04
5.4.40.0070.03512.02
5.4.30.0080.03412.02
5.4.20.0100.03212.02
5.4.10.0080.03312.02
5.4.00.0080.03511.51
5.3.290.0050.04012.80
5.3.280.0100.03512.71
5.3.270.0090.03812.72
5.3.260.0110.03512.73
5.3.250.0040.04112.73
5.3.240.0080.03712.73
5.3.230.0070.03912.72
5.3.220.0100.03512.69
5.3.210.0070.04012.69
5.3.200.0070.03812.69
5.3.190.0060.04612.69
5.3.180.0050.03912.69
5.3.170.0070.03812.68
5.3.160.0080.03512.68
5.3.150.0050.03812.69
5.3.140.0080.03612.67
5.3.130.0080.03912.67
5.3.120.0080.03912.67
5.3.110.0090.03712.68
5.3.100.0050.03812.16
5.3.90.0050.03912.14
5.3.80.0080.03512.13
5.3.70.0060.03712.13
5.3.60.0090.03412.12
5.3.50.0050.03712.06
5.3.40.0060.03712.06
5.3.30.0060.03612.02
5.3.20.0090.03311.80
5.3.10.0090.03311.77
5.3.00.0050.04311.75
5.2.170.0060.0319.23
5.2.160.0090.0359.23
5.2.150.0080.0329.23
5.2.140.0100.0379.23
5.2.130.0050.0409.19
5.2.120.0070.0279.18
5.2.110.0070.0359.19
5.2.100.0060.0299.18
5.2.90.0040.0309.18
5.2.80.0020.0339.18
5.2.70.0080.0289.18
5.2.60.0030.0339.15
5.2.50.0050.0309.11
5.2.40.0060.0299.09
5.2.30.0050.0289.05
5.2.20.0070.0289.05
5.2.10.0060.0268.95
5.2.00.0100.0308.82
5.1.60.0050.0318.10
5.1.50.0060.0308.10
5.1.40.0040.0348.08
5.1.30.0060.0358.43
5.1.20.0050.0368.45
5.1.10.0020.0308.18
5.1.00.0060.0248.18
5.0.50.0020.0296.65
5.0.40.0060.0266.51
5.0.30.0030.0406.32
5.0.20.0020.0216.29
5.0.10.0060.0186.27
5.0.00.0060.0296.27
4.4.90.0050.0144.78
4.4.80.0030.0224.75
4.4.70.0020.0184.75
4.4.60.0040.0154.75
4.4.50.0040.0154.77
4.4.40.0030.0254.71
4.4.30.0040.0154.75
4.4.20.0050.0134.84
4.4.10.0010.0184.85
4.4.00.0040.0244.76
4.3.110.0030.0164.67
4.3.100.0020.0164.67
4.3.90.0030.0164.63
4.3.80.0060.0224.58
4.3.70.0010.0164.63
4.3.60.0030.0144.63
4.3.50.0030.0164.63
4.3.40.0020.0264.54
4.3.30.0040.0153.31
4.3.20.0010.0173.29
4.3.10.0050.0133.25
4.3.00.0030.02715.25

preferences:
50.21 ms | 401 KiB | 5 Q