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.0070.01018.65
8.3.50.0130.00622.03
8.3.40.0120.00318.79
8.3.30.0120.00418.80
8.3.20.0040.00420.25
8.3.10.0040.00421.61
8.3.00.0050.00318.02
8.2.180.0110.00817.00
8.2.170.0110.00422.96
8.2.160.0100.00320.39
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0000.00821.05
8.2.110.0110.01122.01
8.2.100.0060.00618.09
8.2.90.0000.00819.22
8.2.80.0040.00417.97
8.2.70.0000.00817.75
8.2.60.0060.00318.05
8.2.50.0090.00018.07
8.2.40.0090.00018.22
8.2.30.0070.00018.23
8.2.20.0030.00517.90
8.2.10.0040.00418.15
8.2.00.0040.00417.84
8.1.280.0070.00725.92
8.1.270.0080.00023.90
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0060.00322.19
8.1.230.0040.00819.01
8.1.220.0030.00517.77
8.1.210.0040.00418.77
8.1.200.0050.00517.23
8.1.190.0000.00917.23
8.1.180.0040.00418.10
8.1.170.0000.00818.66
8.1.160.0040.00422.06
8.1.150.0040.00418.92
8.1.140.0050.00317.55
8.1.130.0070.00017.97
8.1.120.0000.00717.35
8.1.110.0050.00217.48
8.1.100.0040.00417.52
8.1.90.0000.00717.41
8.1.80.0000.00717.34
8.1.70.0000.00717.43
8.1.60.0030.00517.64
8.1.50.0030.00517.51
8.1.40.0080.00017.57
8.1.30.0030.00617.66
8.1.20.0030.00517.71
8.1.10.0040.00417.61
8.1.00.0040.00417.52
8.0.300.0040.00418.77
8.0.290.0000.00816.88
8.0.280.0070.00018.45
8.0.270.0000.00717.28
8.0.260.0030.00317.27
8.0.250.0030.00516.93
8.0.240.0000.00717.07
8.0.230.0000.00717.00
8.0.220.0030.00316.93
8.0.210.0000.00716.98
8.0.200.0080.00017.04
8.0.190.0000.00817.00
8.0.180.0040.00416.98
8.0.170.0000.00816.99
8.0.160.0080.00017.07
8.0.150.0030.00716.91
8.0.140.0040.00716.93
8.0.130.0110.00013.34
8.0.120.0000.01116.96
8.0.110.0040.00417.00
8.0.100.0000.00717.07
8.0.90.0030.00517.03
8.0.80.0100.00716.96
8.0.70.0000.00816.80
8.0.60.0040.00416.82
8.0.50.0040.00416.97
8.0.30.0070.01317.21
8.0.20.0100.00917.40
8.0.10.0070.00017.06
8.0.00.0060.01216.84
7.4.330.0030.00315.08
7.4.320.0040.00416.47
7.4.300.0030.00316.52
7.4.290.0000.00816.53
7.4.280.0040.00416.43
7.4.270.0070.00016.60
7.4.260.0040.00416.52
7.4.250.0030.00616.43
7.4.240.0040.00416.54
7.4.230.0030.00316.56
7.4.220.0100.00916.55
7.4.210.0070.01416.70
7.4.200.0050.00216.69
7.4.160.0120.00916.54
7.4.150.0080.01117.40
7.4.140.0110.01017.86
7.4.130.0090.00816.57
7.4.120.0090.00816.48
7.4.110.0090.00916.61
7.4.100.0060.01116.39
7.4.90.0180.00016.63
7.4.80.0130.00719.39
7.4.70.0080.01116.39
7.4.60.0130.00316.81
7.4.50.0060.00316.29
7.4.40.0080.01616.49
7.4.30.0070.01416.75
7.4.10.0090.00915.01
7.4.00.0110.00615.10
7.3.330.0020.00213.40
7.3.320.0030.00213.41
7.3.310.0030.00416.40
7.3.300.0000.00716.32
7.3.290.0080.01516.45
7.3.280.0090.00916.42
7.3.270.0160.00317.40
7.3.260.0150.00816.51
7.3.250.0070.01216.46
7.3.240.0100.01616.65
7.3.230.0100.00716.43
7.3.210.0100.00616.51
7.3.200.0130.00919.39
7.3.190.0030.01316.54
7.3.180.0080.00816.66
7.3.170.0110.00616.44
7.3.160.0090.00916.47
7.3.130.0070.01014.96
7.3.120.0040.01115.00
7.3.110.0040.01415.16
7.3.100.0060.00914.89
7.3.90.0060.00614.97
7.3.80.0000.01114.91
7.3.70.0060.00614.94
7.3.60.0030.00914.76
7.3.50.0000.00815.05
7.3.40.0040.01114.98
7.3.30.0030.00714.82
7.3.20.0030.00616.69
7.3.10.0100.00316.74
7.3.00.0000.00916.77
7.2.330.0130.00616.59
7.2.320.0120.00616.88
7.2.310.0000.01716.69
7.2.300.0030.01416.80
7.2.290.0110.00716.54
7.2.260.0070.01115.02
7.2.250.0070.00715.18
7.2.240.0060.00915.11
7.2.230.0070.01114.71
7.2.220.0030.01314.88
7.2.210.0000.01715.14
7.2.200.0000.01315.32
7.2.190.0030.01015.19
7.2.180.0000.01115.25
7.2.170.0000.00915.13
7.2.160.0030.00615.34
7.2.150.0000.01216.97
7.2.140.0080.00816.95
7.2.130.0080.00316.98
7.2.120.0070.00717.14
7.2.110.0030.00616.95
7.2.100.0000.00916.85
7.2.90.0030.01017.07
7.2.80.0040.00816.97
7.2.70.0070.01016.90
7.2.60.0000.01316.80
7.2.50.0070.00317.00
7.2.40.0030.00917.07
7.2.30.0060.00617.14
7.2.20.0130.00016.99
7.2.10.0070.00717.02
7.2.00.0050.00818.15
7.1.330.0060.00916.01
7.1.320.0040.01216.05
7.1.310.0060.00915.86
7.1.300.0140.00015.89
7.1.290.0060.00615.64
7.1.280.0070.00716.05
7.1.270.0040.00815.71
7.1.260.0080.00415.96
7.1.250.0040.00415.85
7.1.240.0000.01115.79
7.1.230.0000.00915.93
7.1.220.0000.01115.64
7.1.210.0040.00415.85
7.1.200.0000.01215.85
7.1.190.0040.00815.89
7.1.180.0060.00615.84
7.1.170.0060.00915.87
7.1.160.0070.00715.89
7.1.150.0000.01315.68
7.1.140.0070.00715.67
7.1.130.0120.00315.96
7.1.120.0000.01215.93
7.1.110.0040.00415.64
7.1.100.0000.01016.91
7.1.90.0090.00915.73
7.1.80.0070.00715.73
7.1.70.0010.00816.55
7.1.60.0070.01317.40
7.1.50.0050.00616.31
7.1.40.0060.00615.84
7.1.30.0070.00715.86
7.1.20.0060.00316.05
7.1.10.0030.00715.57
7.1.00.0060.04119.13
7.0.330.0030.00615.36
7.0.320.0070.00715.36
7.0.310.0090.00615.48
7.0.300.0060.01015.36
7.0.290.0080.00815.19
7.0.280.0030.00915.37
7.0.270.0030.00915.61
7.0.260.0090.00615.43
7.0.250.0030.01015.28
7.0.240.0060.00915.25
7.0.230.0070.01015.55
7.0.220.0060.00915.57
7.0.210.0000.01115.35
7.0.200.0060.00616.11
7.0.190.0080.00315.19
7.0.180.0030.01015.27
7.0.170.0040.01115.11
7.0.160.0110.00315.34
7.0.150.0030.01315.47
7.0.140.0040.04118.81
7.0.130.0100.00315.23
7.0.120.0040.00415.35
7.0.110.0030.00715.20
7.0.100.0100.00315.58
7.0.90.0070.00715.32
7.0.80.0070.00415.38
7.0.70.0100.00715.44
7.0.60.0070.04017.71
7.0.50.0070.04516.58
7.0.40.0090.04416.79
7.0.30.0280.03516.76
7.0.20.0200.03016.82
7.0.10.0070.04616.91
7.0.00.0120.04016.81
5.6.400.0030.01014.68
5.6.390.0120.00314.53
5.6.380.0110.00414.71
5.6.370.0000.01014.43
5.6.360.0040.00814.56
5.6.350.0030.00614.45
5.6.340.0030.01014.62
5.6.330.0090.00914.13
5.6.320.0030.00914.50
5.6.310.0030.01014.52
5.6.300.0030.01014.31
5.6.290.0030.00914.48
5.6.280.0030.04317.64
5.6.270.0070.00714.14
5.6.260.0080.00414.56
5.6.250.0040.01114.57
5.6.240.0030.01214.59
5.6.230.0040.01014.42
5.6.220.0060.01014.59
5.6.210.0050.02617.46
5.6.200.0050.04516.37
5.6.190.0080.02317.64
5.6.180.0130.02317.55
5.6.170.0130.04517.50
5.6.160.0050.04417.48
5.6.150.0070.02716.26
5.6.140.0030.03416.22
5.6.130.0070.02316.33
5.6.120.0060.02317.70
5.6.110.0070.03517.63
5.6.100.0040.02917.70
5.6.90.0080.03817.63
5.6.80.0100.03817.55
5.6.70.0070.00714.41
5.6.60.0090.00314.31
5.6.50.0130.00314.30
5.6.40.0030.00914.38
5.6.30.0060.00914.11
5.6.20.0030.00614.15
5.6.10.0070.01114.41
5.6.00.0040.01214.34
5.5.380.0000.01114.59
5.5.370.0000.01414.12
5.5.360.0090.00614.45
5.5.350.0050.02917.32
5.5.340.0080.04116.15
5.5.330.0160.03717.51
5.5.320.0060.04117.42
5.5.310.0220.04117.37
5.5.300.0070.04616.05
5.5.290.0050.02316.15
5.5.280.0070.04517.66
5.5.270.0070.03017.61
5.5.260.0150.03517.46
5.5.250.0080.04317.64
5.5.240.2080.02317.32
5.5.230.0000.01214.40
5.5.220.0090.00014.33
5.5.210.0000.01514.37
5.5.200.0040.00714.19
5.5.190.0130.00014.46
5.5.180.0080.00314.13
5.5.170.0060.00914.31
5.5.160.0070.00714.16
5.5.150.0040.00814.48
5.5.140.0070.00714.30
5.5.130.0040.01214.42
5.5.120.0120.00314.63
5.5.110.0030.00914.41
5.5.100.0060.00614.15
5.5.90.0030.00914.17
5.5.80.0100.00314.47
5.5.70.0070.00714.69
5.5.60.0000.01214.47
5.5.50.0100.01014.48
5.5.40.0030.01214.11
5.5.30.0070.00714.32
5.5.20.0040.01114.51
5.5.10.0040.01114.45
5.5.00.0070.00714.09
5.4.450.0160.02215.53
5.4.440.0260.02315.44
5.4.430.0130.02715.18
5.4.420.0100.02715.40
5.4.410.0570.02715.21
5.4.400.0160.02615.05
5.4.390.0320.01915.10
5.4.380.0140.02814.85
5.4.370.0130.02714.81
5.4.360.0110.02814.76
5.4.350.0080.03614.76
5.4.340.0130.03014.84
5.4.330.0090.00611.07
5.4.320.0040.02111.84
5.4.310.0040.02411.90
5.4.300.0080.02111.68
5.4.290.0060.02211.85
5.4.280.0060.02311.80
5.4.270.0050.02211.64
5.4.260.0100.01911.74
5.4.250.0060.02411.84
5.4.240.0020.02411.77
5.4.230.0090.02311.73
5.4.220.0040.03011.74
5.4.210.0050.02411.81
5.4.200.0080.01911.79
5.4.190.0060.02111.78
5.4.180.0060.02311.76
5.4.170.0070.02811.77
5.4.160.0090.02711.59
5.4.150.0070.02711.70
5.4.140.0060.02311.66
5.4.130.0070.02111.57
5.4.120.0060.02211.41
5.4.110.0040.02411.66
5.4.100.0120.01811.50
5.4.90.0070.01911.59
5.4.80.0050.02311.44
5.4.70.0040.02211.57
5.4.60.0040.02211.40
5.4.50.0060.01911.48
5.4.40.0050.02211.62
5.4.30.0020.02511.60
5.4.20.0080.02011.45
5.4.10.0030.02411.60
5.4.00.0070.01911.34
5.3.290.0040.02411.82
5.3.280.0040.02411.68
5.3.270.0050.02511.72
5.3.260.0060.02611.64
5.3.250.0080.02211.74
5.3.240.0020.02711.57
5.3.230.0040.02311.57
5.3.220.0050.02311.53
5.3.210.0070.02211.62
5.3.200.0060.02111.62
5.3.190.0050.02111.65
5.3.180.0060.02911.62
5.3.170.0030.02511.62
5.3.160.0040.02211.75
5.3.150.0070.02011.62
5.3.140.0050.02311.70
5.3.130.0020.02611.69
5.3.120.0030.02511.71
5.3.110.0070.02111.61
5.3.100.0070.02111.44
5.3.90.0070.02311.53
5.3.80.0060.02211.25
5.3.70.0040.02711.24
5.3.60.0070.02711.37
5.3.50.0050.02611.36
5.3.40.0080.02411.29
5.3.30.0080.02111.36
5.3.20.0070.02311.24
5.3.10.0080.01911.12
5.3.00.0080.02211.15
5.2.170.0030.0379.23
5.2.160.0050.0309.23
5.2.150.0040.0339.23
5.2.140.0060.0329.23
5.2.130.0060.0409.18
5.2.120.0040.0359.19
5.2.110.0070.0329.19
5.2.100.0060.0319.18
5.2.90.0070.0309.18
5.2.80.0030.0329.18
5.2.70.0040.0419.18
5.2.60.0060.0349.14
5.2.50.0080.0369.11
5.2.40.0050.0349.09
5.2.30.0030.0369.05
5.2.20.0100.0339.05
5.2.10.0060.0378.95
5.2.00.0060.0308.81
5.1.60.0040.0248.10
5.1.50.0050.0248.10
5.1.40.0030.0258.07
5.1.30.0040.0268.43
5.1.20.0060.0278.45
5.1.10.0050.0288.17
5.1.00.0040.0288.18
5.0.50.0050.0206.66
5.0.40.0090.0216.51
5.0.30.0070.0396.32
5.0.20.0050.0236.29
5.0.10.0050.0196.27
5.0.00.0030.0316.27
4.4.90.0040.0184.78
4.4.80.0050.0194.75
4.4.70.0050.0194.76
4.4.60.0050.0194.75
4.4.50.0040.0164.77
4.4.40.0040.0254.71
4.4.30.0030.0174.76
4.4.20.0020.0214.84
4.4.10.0060.0144.85
4.4.00.0020.0264.76
4.3.110.0050.0134.67
4.3.100.0010.0174.66
4.3.90.0010.0164.64
4.3.80.0020.0244.58
4.3.70.0050.0124.63
4.3.60.0030.0144.63
4.3.50.0040.0154.63
4.3.40.0050.0244.54
4.3.30.0040.0143.31
4.3.20.0030.0173.29
4.3.10.0050.0173.25
4.3.00.0100.02015.25

preferences:
42.42 ms | 401 KiB | 5 Q