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); } // no state $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); }; // stream state $pos = 0; $char = $in[0]; $peek = function() use ($in, &$pos, $len) { if ($pos+1 >= $len) { return null; } return $in[$pos+1]; }; $next = function() use ($peek, &$pos, &$char) { $char = $peek(); $pos++; return $char !== null; }; // lex state $out = ''; $find_start = function () use (&$char, $next) { while (!$alpha_num($char)) { if (!$next()) { return null; } } echo "START: $char"; return null; }; $state = $find_start; 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.43
8.3.50.0110.00821.92
8.3.40.0110.00718.97
8.3.30.0110.00419.23
8.3.20.0070.00020.14
8.3.10.0040.00421.89
8.3.00.0040.00417.93
8.2.180.0120.00918.79
8.2.170.0070.01322.96
8.2.160.0040.01220.39
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0000.00821.01
8.2.110.0060.00322.04
8.2.100.0080.00418.03
8.2.90.0030.00619.35
8.2.80.0000.00817.97
8.2.70.0050.00317.71
8.2.60.0040.00417.93
8.2.50.0030.00618.07
8.2.40.0030.00518.22
8.2.30.0000.00718.24
8.2.20.0040.00417.89
8.2.10.0000.00718.01
8.2.00.0060.00317.77
8.1.280.0110.00725.92
8.1.270.0000.00923.99
8.1.260.0040.01426.35
8.1.250.0040.00428.09
8.1.240.0030.00623.95
8.1.230.0040.00823.93
8.1.220.0000.00817.78
8.1.210.0030.00618.77
8.1.200.0060.00317.35
8.1.190.0030.00517.35
8.1.180.0030.00618.10
8.1.170.0050.00318.70
8.1.160.0040.00422.02
8.1.150.0000.00818.93
8.1.140.0030.00517.34
8.1.130.0030.00317.84
8.1.120.0000.00717.41
8.1.110.0070.00017.36
8.1.100.0050.00317.49
8.1.90.0000.00717.49
8.1.80.0040.00417.48
8.1.70.0030.00317.40
8.1.60.0040.00417.53
8.1.50.0040.00417.59
8.1.40.0040.00417.43
8.1.30.0040.00417.66
8.1.20.0050.00317.56
8.1.10.0080.00017.54
8.1.00.0000.00717.38
8.0.300.0050.00318.77
8.0.290.0050.00216.75
8.0.280.0000.00718.33
8.0.270.0000.00717.22
8.0.260.0050.00317.27
8.0.250.0030.00317.02
8.0.240.0030.00317.04
8.0.230.0000.00716.90
8.0.220.0000.00716.96
8.0.210.0000.00816.94
8.0.200.0000.01217.01
8.0.190.0080.00017.05
8.0.180.0040.00417.00
8.0.170.0000.00816.90
8.0.160.0000.00716.94
8.0.150.0060.00516.77
8.0.140.0000.00916.89
8.0.130.0030.00313.43
8.0.120.0040.00416.88
8.0.110.0000.00816.96
8.0.100.0040.00416.84
8.0.90.0050.00317.10
8.0.80.0030.01716.86
8.0.70.0040.00417.09
8.0.60.0040.00417.04
8.0.50.0040.00416.85
8.0.30.0090.01017.22
8.0.20.0120.00917.40
8.0.10.0040.00416.95
8.0.00.0070.01216.85
7.4.330.0000.00615.02
7.4.320.0060.00016.63
7.4.300.0000.00616.57
7.4.290.0040.00416.61
7.4.280.0000.00716.64
7.4.270.0000.00716.64
7.4.260.0070.00016.51
7.4.250.0000.00816.41
7.4.240.0000.00716.54
7.4.230.0000.00616.37
7.4.220.0070.01316.46
7.4.210.0070.00716.70
7.4.200.0000.00716.40
7.4.160.0140.00316.53
7.4.150.0080.01117.40
7.4.140.0120.00817.86
7.4.130.0110.01016.74
7.4.120.0100.00716.67
7.4.110.0040.01516.61
7.4.100.0110.01316.38
7.4.90.0070.01116.43
7.4.80.0100.01319.39
7.4.70.0200.00316.42
7.4.60.0100.00616.54
7.4.50.0000.00416.23
7.4.40.0030.01316.57
7.4.30.0130.00716.52
7.4.10.0100.01015.13
7.4.00.0050.01115.01
7.3.330.0000.00613.46
7.3.320.0000.00513.39
7.3.310.0030.00316.27
7.3.300.0040.00416.38
7.3.290.0130.00716.47
7.3.280.0120.00716.45
7.3.270.0170.00017.40
7.3.260.0060.01216.45
7.3.250.0120.00716.49
7.3.240.0100.00716.59
7.3.230.0140.00316.39
7.3.210.0060.01016.56
7.3.200.0120.00319.39
7.3.190.0070.01316.67
7.3.180.0080.00816.48
7.3.170.0070.01716.58
7.3.160.0040.01116.36
7.3.130.0060.01214.93
7.3.120.0080.00715.15
7.3.110.0030.01714.77
7.3.100.0060.00915.14
7.3.90.0070.00714.78
7.3.80.0000.00815.01
7.3.70.0030.00615.02
7.3.60.0030.01514.87
7.3.50.0040.01514.70
7.3.40.0140.00414.91
7.3.30.0130.00014.84
7.3.20.0060.00916.50
7.3.10.0120.00416.77
7.3.00.0090.00616.65
7.2.330.0100.00916.73
7.2.320.0120.00616.78
7.2.310.0070.01016.46
7.2.300.0110.01116.39
7.2.290.0100.00716.73
7.2.260.0100.01015.20
7.2.250.0110.00715.14
7.2.240.0070.01015.29
7.2.230.0040.01215.18
7.2.220.0060.01215.23
7.2.210.0030.01015.07
7.2.200.0090.00615.21
7.2.190.0070.01315.18
7.2.180.0030.00915.27
7.2.170.0110.00414.99
7.2.160.0070.00715.19
7.2.150.0070.01116.65
7.2.140.0080.00817.01
7.2.130.0080.00617.06
7.2.120.0100.00716.86
7.2.110.0140.00116.89
7.2.100.0090.00616.96
7.2.90.0040.00816.98
7.2.80.0060.00917.00
7.2.70.0100.00616.99
7.2.60.0070.00616.92
7.2.50.0070.00717.06
7.2.40.0060.00616.89
7.2.30.0020.01217.03
7.2.20.0100.00316.87
7.2.10.0050.00816.90
7.2.00.0070.00617.59
7.1.330.0040.01115.71
7.1.320.0090.00615.99
7.1.310.0030.01015.54
7.1.300.0080.00815.88
7.1.290.0040.01015.86
7.1.280.0070.00715.58
7.1.270.0040.00815.55
7.1.260.0030.01315.79
7.1.250.0080.00515.74
7.1.240.0100.00315.78
7.1.230.0040.01115.76
7.1.220.0030.00915.84
7.1.210.0030.00615.71
7.1.200.0060.00515.73
7.1.190.0070.00715.83
7.1.180.0060.00315.87
7.1.170.0000.01415.96
7.1.160.0070.00415.49
7.1.150.0000.01315.56
7.1.140.0000.01115.49
7.1.130.0100.00315.75
7.1.120.0030.00615.80
7.1.110.0030.01016.01
7.1.100.0050.00517.14
7.1.90.0060.00615.84
7.1.80.0060.00315.74
7.1.70.0060.00616.46
7.1.60.0090.01017.63
7.1.50.0100.01016.32
7.1.40.0000.01015.84
7.1.30.0000.01015.79
7.1.20.0060.00615.79
7.1.10.0070.00715.73
7.1.00.0000.04419.07
7.0.330.0080.00015.41
7.0.320.0040.00415.59
7.0.310.0040.00715.45
7.0.300.0000.00815.47
7.0.290.0100.00015.60
7.0.280.0060.00615.30
7.0.270.0030.01015.39
7.0.260.0050.00515.48
7.0.250.0060.00615.43
7.0.240.0070.00715.51
7.0.230.0150.00315.60
7.0.220.0040.00715.51
7.0.210.0070.00715.59
7.0.200.0080.00516.05
7.0.190.0070.00715.54
7.0.180.0140.00015.59
7.0.170.0040.00715.51
7.0.160.0000.01315.55
7.0.150.0040.00415.54
7.0.140.0070.04018.72
7.0.130.0040.01115.35
7.0.120.0000.01315.66
7.0.110.0080.00015.51
7.0.100.0060.00315.34
7.0.90.0070.00715.56
7.0.80.0060.00915.18
7.0.70.0090.00015.46
7.0.60.0070.04517.81
7.0.50.0090.02216.70
7.0.40.0100.04216.91
7.0.30.0170.03516.74
7.0.20.0120.02517.01
7.0.10.0100.03616.93
7.0.00.0100.02516.88
5.6.400.0030.01014.65
5.6.390.0030.01014.68
5.6.380.0070.00714.10
5.6.370.0040.01114.65
5.6.360.0030.00614.58
5.6.350.0030.01014.47
5.6.340.0030.01014.66
5.6.330.0040.01114.40
5.6.320.0090.00614.27
5.6.310.0130.00014.35
5.6.300.0030.01114.42
5.6.290.0000.01014.36
5.6.280.0020.04417.54
5.6.270.0060.00914.25
5.6.260.0000.00814.75
5.6.250.0070.00714.25
5.6.240.0060.00614.35
5.6.230.0100.01014.64
5.6.220.0070.00714.19
5.6.210.0080.02517.54
5.6.200.0070.04816.32
5.6.190.0080.04817.31
5.6.180.2100.02317.51
5.6.170.0130.04117.52
5.6.160.0030.04917.47
5.6.150.0050.04516.39
5.6.140.0080.03616.33
5.6.130.0040.02516.35
5.6.120.0110.01817.68
5.6.110.0100.04317.75
5.6.100.0100.03217.67
5.6.90.0070.04117.76
5.6.80.0090.04417.29
5.6.70.0170.03917.40
5.6.60.0060.00314.18
5.6.50.0030.01014.39
5.6.40.0100.00614.26
5.6.30.0060.00914.33
5.6.20.0070.00314.18
5.6.10.0060.00614.34
5.6.00.0120.00314.26
5.5.380.0000.02014.24
5.5.370.0060.00914.21
5.5.360.0000.01514.35
5.5.350.0060.02617.32
5.5.340.0080.02816.06
5.5.330.0090.02317.06
5.5.320.0230.04117.38
5.5.310.0210.03017.25
5.5.300.0040.04916.06
5.5.290.0070.04416.11
5.5.280.0030.04717.56
5.5.270.0030.05017.50
5.5.260.0080.03817.54
5.5.250.0050.05017.54
5.5.240.0090.04017.07
5.5.230.0090.00314.20
5.5.220.0030.00714.19
5.5.210.0060.01114.19
5.5.200.0030.01314.33
5.5.190.0070.00414.09
5.5.180.0060.00614.23
5.5.170.0030.00614.27
5.5.160.0060.00614.29
5.5.150.0000.01113.93
5.5.140.0060.00914.21
5.5.130.0120.00314.48
5.5.120.0030.00814.41
5.5.110.0080.00314.20
5.5.100.0000.01514.31
5.5.90.0030.01014.36
5.5.80.0030.01014.25
5.5.70.0030.00814.30
5.5.60.0080.00413.99
5.5.50.0000.01113.98
5.5.40.0040.00414.02
5.5.30.0090.00314.07
5.5.20.0000.01014.45
5.5.10.0070.00714.40
5.5.00.0120.00314.24
5.4.450.0430.02815.87
5.4.440.0330.03315.88
5.4.430.0350.02715.95
5.4.420.0280.03215.89
5.4.410.0230.03315.80
5.4.400.0300.03215.62
5.4.390.0310.02815.70
5.4.380.0070.03215.41
5.4.370.0030.02615.50
5.4.360.0050.02115.52
5.4.350.0080.01812.14
5.4.340.0060.02312.14
5.4.330.0060.00612.24
5.4.320.0040.02312.38
5.4.310.0040.02312.38
5.4.300.0070.02212.38
5.4.290.0020.02712.38
5.4.280.0060.02312.33
5.4.270.0020.02112.33
5.4.260.0040.02312.33
5.4.250.0050.03112.33
5.4.240.0050.02112.33
5.4.230.0020.02712.32
5.4.220.0040.02112.32
5.4.210.0040.02212.32
5.4.200.0040.02512.32
5.4.190.0080.02312.32
5.4.180.0040.02412.32
5.4.170.0040.02112.33
5.4.160.0040.02112.33
5.4.150.0040.02312.32
5.4.140.0090.02212.16
5.4.130.0040.02212.16
5.4.120.0070.01912.14
5.4.110.0040.02012.14
5.4.100.0020.02312.14
5.4.90.0040.02112.14
5.4.80.0020.02412.14
5.4.70.0060.02012.13
5.4.60.0050.01912.13
5.4.50.0060.02212.14
5.4.40.0060.01912.13
5.4.30.0050.02012.13
5.4.20.0080.01812.13
5.4.10.0040.02012.13
5.4.00.0060.02211.88
5.3.290.0030.02412.52
5.3.280.0070.02312.48
5.3.270.0060.02112.48
5.3.260.0030.02412.48
5.3.250.0040.02312.48
5.3.240.0020.02712.48
5.3.230.0040.02412.48
5.3.220.0060.02312.46
5.3.210.0020.02412.47
5.3.200.0040.02212.46
5.3.190.0060.02012.46
5.3.180.0030.02212.46
5.3.170.0050.02112.46
5.3.160.0040.02612.46
5.3.150.0070.02612.46
5.3.140.0070.02612.46
5.3.130.0040.03012.45
5.3.120.0040.02612.45
5.3.110.0060.02112.46
5.3.100.0060.01912.20
5.3.90.0020.02412.19
5.3.80.0040.02312.18
5.3.70.0060.01912.18
5.3.60.0040.02212.18
5.3.50.0030.02212.15
5.3.40.0050.02012.15
5.3.30.0080.02212.13
5.3.20.0050.02612.02
5.3.10.0040.02212.00
5.3.00.0040.02112.00
5.2.170.0060.0299.23
5.2.160.0050.0289.23
5.2.150.0060.0339.23
5.2.140.0050.0349.22
5.2.130.0060.0359.19
5.2.120.0060.0299.18
5.2.110.0060.0279.20
5.2.100.0040.0299.18
5.2.90.0070.0359.19
5.2.80.0020.0339.18
5.2.70.0080.0279.18
5.2.60.0030.0329.14
5.2.50.0030.0339.11
5.2.40.0030.0319.09
5.2.30.0060.0299.06
5.2.20.0060.0289.04
5.2.10.0070.0278.95
5.2.00.0060.0298.82
5.1.60.0070.0278.10
5.1.50.0060.0238.10
5.1.40.0040.0258.08
5.1.30.0040.0268.43
5.1.20.0050.0298.45
5.1.10.0060.0258.18
5.1.00.0070.0238.17
5.0.50.0030.0226.65
5.0.40.0030.0216.51
5.0.30.0010.0346.33
5.0.20.0030.0196.29
5.0.10.0040.0196.27
5.0.00.0050.0306.26
4.4.90.0020.0164.78
4.4.80.0010.0164.75
4.4.70.0030.0164.76
4.4.60.0020.0164.75
4.4.50.0050.0134.77
4.4.40.0020.0274.71
4.4.30.0040.0154.75
4.4.20.0060.0124.84
4.4.10.0020.0164.85
4.4.00.0030.0254.76
4.3.110.0020.0174.66
4.3.100.0050.0134.66
4.3.90.0030.0154.64
4.3.80.0030.0244.58
4.3.70.0020.0154.63
4.3.60.0050.0164.63
4.3.50.0020.0204.63
4.3.40.0040.0264.54
4.3.30.0000.0213.31
4.3.20.0020.0163.29
4.3.10.0020.0163.25
4.3.00.0000.0237.16

preferences:
48.22 ms | 401 KiB | 5 Q