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 = array(); $find_word = null; $upper_word = null; $lower_word = null; $cap_word = null; $num_word = null; $find_word = function () use (&$char, $alpha_num, $lower, $upper, $next, $peek, &$lower_word, &$upper_word, &$cap_word, &$num_word) { while (!$alpha_num($char)) { if (!$next()) { return null; } } if ($lower($char)) { return $lower_word; } if ($upper($char)) { if ($upper($peek())) { // uppercase word return $upper_word; } return $cap_word; // capitalized word } return $num_word; }; $upper_word = function() use (&$out, &$char, $next, $upper, &$find_word) { $word = $char; while ($next() && $upper($char)) { $word .= $char; } $out[] = $word; return $find_word; }; $state = $find_word; while ($state !== null) { $state = $state(); } return strtolower(implode('_', $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.70.0130.00918.43
8.3.60.0070.01418.30
8.3.50.0070.01022.11
8.3.40.0120.00618.89
8.3.30.0090.00619.22
8.3.20.0000.00820.39
8.3.10.0050.00321.86
8.3.00.0080.00018.04
8.2.180.0090.00616.63
8.2.170.0110.00422.96
8.2.160.0060.01220.70
8.2.150.0030.00524.18
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0120.00620.99
8.2.110.0030.00622.16
8.2.100.0120.00018.28
8.2.90.0040.00419.28
8.2.80.0090.00017.97
8.2.70.0040.00417.61
8.2.60.0080.00018.18
8.2.50.0030.00618.07
8.2.40.0050.00318.17
8.2.30.0040.00418.52
8.2.20.0030.00517.78
8.2.10.0050.00218.13
8.2.00.0050.00317.79
8.1.280.0040.01125.92
8.1.270.0040.00423.89
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0040.00423.73
8.1.230.0080.00319.22
8.1.220.0000.00817.91
8.1.210.0090.00018.77
8.1.200.0070.00317.25
8.1.190.0030.00517.13
8.1.180.0050.00318.10
8.1.170.0040.00418.56
8.1.160.0070.00022.18
8.1.150.0040.00418.98
8.1.140.0000.00817.55
8.1.130.0030.00317.96
8.1.120.0000.00717.57
8.1.110.0040.00417.45
8.1.100.0030.00317.59
8.1.90.0040.00417.55
8.1.80.0050.00217.50
8.1.70.0040.00417.44
8.1.60.0050.00317.61
8.1.50.0040.00417.54
8.1.40.0040.00417.60
8.1.30.0000.00817.75
8.1.20.0080.00017.65
8.1.10.0030.00517.64
8.1.00.0080.00017.63
8.0.300.0040.00418.77
8.0.290.0070.00017.00
8.0.280.0000.00718.62
8.0.270.0040.00417.27
8.0.260.0060.00017.27
8.0.250.0000.00717.02
8.0.240.0000.00717.01
8.0.230.0030.00317.08
8.0.220.0030.00316.96
8.0.210.0000.00717.04
8.0.200.0040.00417.13
8.0.190.0050.00317.10
8.0.180.0000.00817.10
8.0.170.0080.00017.13
8.0.160.0000.00816.88
8.0.150.0040.00417.04
8.0.140.0000.01017.07
8.0.130.0030.00313.47
8.0.120.0050.00316.97
8.0.110.0080.00017.04
8.0.100.0080.00016.94
8.0.90.0080.00016.95
8.0.80.0090.00617.10
8.0.70.0000.00717.02
8.0.60.0040.00416.93
8.0.50.0040.00416.94
8.0.30.0080.01117.31
8.0.20.0140.00917.40
8.0.10.0040.00417.04
8.0.00.0080.01016.74
7.4.330.0030.00315.08
7.4.320.0070.00016.66
7.4.300.0030.00316.67
7.4.290.0030.00616.73
7.4.280.0030.00316.54
7.4.270.0050.00216.53
7.4.260.0000.00816.62
7.4.250.0030.00616.66
7.4.240.0010.00616.58
7.4.230.0030.00316.53
7.4.220.0130.01316.54
7.4.210.0100.01016.75
7.4.200.0070.00016.49
7.4.160.0100.00616.61
7.4.150.0070.01017.40
7.4.140.0080.00817.86
7.4.130.0150.00516.62
7.4.120.0120.00516.57
7.4.110.0070.01116.77
7.4.100.0060.01616.59
7.4.90.0060.01216.57
7.4.80.0130.01019.39
7.4.70.0070.01716.61
7.4.60.0060.00916.66
7.4.50.0000.00816.61
7.4.40.0100.00716.36
7.4.30.0070.01016.60
7.4.00.0030.01015.08
7.3.330.0050.00013.32
7.3.320.0060.00013.30
7.3.310.0030.00316.48
7.3.300.0050.00316.32
7.3.290.0150.00616.45
7.3.280.0050.01316.44
7.3.270.0070.01117.40
7.3.260.0070.01016.43
7.3.250.0150.00616.59
7.3.240.0120.00616.43
7.3.230.0110.01116.48
7.3.210.0060.01016.64
7.3.200.0060.01319.39
7.3.190.0080.00816.41
7.3.180.0120.00916.67
7.3.170.0110.01116.80
7.3.160.0110.00516.46
7.3.120.0030.00715.05
7.2.330.0090.00916.55
7.2.320.0120.00816.84
7.2.310.0070.01116.85
7.2.300.0150.00916.70
7.2.290.0100.01016.63
7.1.100.0000.01118.30
7.1.70.0030.00617.08
7.1.60.0160.00919.25
7.1.50.0070.01416.94
7.1.00.0100.07022.40
7.0.200.0000.00716.75
7.0.140.0070.07322.08
7.0.120.0000.07322.10
7.0.110.0030.07722.07
7.0.100.0030.05722.08
7.0.90.0030.07722.12
7.0.80.0030.07322.04
7.0.70.0130.06022.14
7.0.60.0070.07022.12
7.0.50.0070.07022.13
7.0.40.0030.06022.09
7.0.30.0030.07322.12
7.0.20.0100.06721.96
7.0.10.0000.07322.18
7.0.00.0000.06022.20
5.6.280.0000.07721.18
5.6.260.0070.06320.84
5.6.250.0000.07721.05
5.6.240.0000.08321.14
5.6.230.0030.07720.98
5.6.220.0030.07321.13
5.6.210.0070.06721.07
5.6.200.0000.08020.97
5.6.190.0030.06721.13
5.6.180.0000.07720.88
5.6.170.0070.05721.08
5.6.160.0070.07020.98
5.6.150.0030.07021.09
5.6.140.0070.07320.84
5.6.130.0070.05021.05
5.6.120.0070.07021.08
5.6.110.0030.07721.06
5.6.100.0030.07320.88
5.6.90.0070.07020.78
5.6.80.0100.05320.36
5.6.70.0100.06320.35
5.6.60.0030.07020.50
5.6.50.0030.06720.36
5.6.40.0030.05320.49
5.6.30.0070.06720.21
5.6.20.0070.07020.25
5.6.10.0000.07320.38
5.6.00.0070.06720.13
5.5.380.0000.07017.59
5.5.370.0000.07017.60
5.5.360.0070.07017.67
5.5.350.0000.07017.50
5.5.340.0000.07717.95
5.5.330.0070.05317.87
5.5.320.0030.07017.97
5.5.310.0100.06318.23
5.5.300.0070.06718.05
5.5.290.0000.07318.25
5.5.280.0000.05317.99
5.5.270.0100.07018.22
5.5.260.0070.07317.93
5.5.250.0070.07017.68
5.5.240.0070.06017.25
5.5.230.0070.06717.54
5.5.220.0000.07317.61
5.5.210.0000.06717.60
5.5.200.0100.04717.34
5.5.190.0030.06017.32
5.5.180.0030.07317.45
5.5.160.0030.05717.30
5.5.150.0030.05317.51
5.5.140.0030.06717.31
5.5.130.0070.06317.29
5.5.120.0100.06317.57
5.5.110.0070.06317.29
5.5.100.0030.07317.48
5.5.90.0000.07317.11
5.5.80.0000.05317.47
5.5.70.0030.03317.21
5.5.60.0000.06017.46
5.5.50.0000.07017.34
5.5.40.0130.06017.34
5.5.30.0030.05017.36
5.5.20.0000.07717.29
5.5.10.0030.07017.34
5.5.00.0000.05317.33
5.4.450.0030.06719.57
5.4.440.0030.07319.27
5.4.430.0000.07319.48
5.4.420.0070.06019.63
5.4.410.0030.06319.18
5.4.400.0030.06319.34
5.4.390.0000.07019.34
5.4.380.0030.06719.19
5.4.370.0070.05319.31
5.4.360.0030.06719.01
5.4.350.0070.06319.25
5.4.340.0000.07719.01
5.4.320.0100.06319.31
5.4.310.0070.05019.00
5.4.300.0030.06719.33
5.4.290.0000.07318.98
5.4.280.0000.07319.16
5.4.270.0000.07019.32
5.4.260.0070.06018.99
5.4.250.0100.06319.24
5.4.240.0000.03719.25
5.4.230.0030.06719.08
5.4.220.0000.07719.30
5.4.210.0000.07018.93
5.4.200.0070.05719.02
5.4.190.0070.05319.00
5.4.180.0000.06019.32
5.4.170.0030.04719.13
5.4.160.0070.06318.99
5.4.150.0030.07319.01
5.4.140.0030.06316.39
5.4.130.0070.06316.60
5.4.120.0030.06316.43
5.4.110.0030.06716.60
5.4.100.0100.05016.66
5.4.90.0000.06716.59
5.4.80.0070.05716.53
5.4.70.0070.05316.54
5.4.60.0070.06316.58
5.4.50.0070.06016.52
5.4.40.0000.06716.34
5.4.30.0000.06316.42
5.4.20.0070.06016.38
5.4.10.0000.04016.38
5.4.00.0030.05315.98
5.3.290.0000.07714.82
5.3.280.0000.07014.86
5.3.270.0030.06314.82
5.3.260.0030.05714.77
5.3.250.0000.07014.87
5.3.240.0000.07014.73
5.3.230.0030.06714.69
5.3.220.0070.06314.73
5.3.210.0030.07014.56
5.3.200.0100.05314.55
5.3.190.0000.06714.93
5.3.180.0000.06314.66
5.3.170.0030.05714.71
5.3.160.0030.06314.79
5.3.150.0030.06714.65
5.3.140.0030.06714.92
5.3.130.0030.06714.72
5.3.120.0030.05314.91
5.3.110.0030.04314.76
5.3.100.0070.05014.20
5.3.90.0130.05714.15
5.3.80.0030.05714.14
5.3.70.0000.06714.23
5.3.60.0030.06714.13
5.3.50.0000.05714.17
5.3.40.0030.06314.07
5.3.30.0030.05014.02
5.3.20.0070.05013.84
5.3.10.0000.05713.92
5.3.00.0030.05013.78
5.2.170.0000.06011.28
5.2.160.0070.04311.14
5.2.150.0030.05311.14
5.2.140.0030.05711.29
5.2.130.0030.05311.17
5.2.120.0000.05711.19
5.2.110.0000.05711.12
5.2.100.0030.05311.23
5.2.90.0000.05311.17
5.2.80.0030.04311.23
5.2.70.0030.05311.16
5.2.60.0030.05011.14
5.2.50.0070.04711.03
5.2.40.0030.04710.96
5.2.30.0030.04010.83
5.2.20.0000.04710.96
5.2.10.0070.05010.86
5.2.00.0000.05310.80
5.1.60.0000.05010.28
5.1.50.0000.04010.28
5.1.40.0030.04310.28
5.1.30.0000.05010.35
5.1.20.0000.05310.39
5.1.10.0100.04010.33
5.1.00.0070.03710.28
5.0.50.0030.04010.28
5.0.40.0030.03710.28
5.0.30.0000.06010.28
5.0.20.0030.03710.28
5.0.10.0000.03710.28
5.0.00.0030.05310.28
4.4.90.0000.02710.28
4.4.80.0000.03010.28
4.4.70.0000.03010.28
4.4.60.0000.03010.28
4.4.50.0000.02710.28
4.4.40.0000.03010.28
4.4.30.0030.01310.28
4.4.20.0000.03010.28
4.4.10.0000.03010.28
4.4.00.0000.04310.28
4.3.110.0000.03010.28
4.3.100.0000.03010.28
4.3.90.0000.03010.28
4.3.80.0000.04710.28
4.3.70.0000.03010.28
4.3.60.0000.03010.28
4.3.50.0000.02710.28
4.3.40.0000.04710.28
4.3.30.0030.02310.28
4.3.20.0000.02710.28
4.3.10.0000.02710.28
4.3.00.0000.02010.28

preferences:
35.88 ms | 401 KiB | 5 Q