3v4l.org

run code in 300+ PHP versions simultaneously
<?php // produces the expected result echo transpose("F#sus7/C#",3); function transpose($chord,$transpose) { // the chords $chords = array("C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"); $result = ""; // get root tone $root_arr = explode("/",$chord); $root = strtoupper($root_arr[0]); // the chord is the first character and a # if there is one $root = $root[0].((strpos($root, "#") !== false)?"#":""); // get any extra info $root_extra_info = str_replace("#","",substr($root_arr[0],1)); // assuming that extra info does not have any # // find the index on chords array $root_index = array_search($root,$chords); // transpose the values and modulo by 12 so we always point to existing indexes in our array $root_transpose_index = floor(($root_index + $transpose) % 12); if ($root_transpose_index < 0) { $root_transpose_index += 12; } $result.= $chords[$root_transpose_index].$root_extra_info; if(count($root_arr)>1) { // get the non root tone $non_root = $root_arr[1]; // the chord is the first character and a # if there is one $non_root = strtoupper($non_root[0]).((strpos($non_root, "#") !== false)?"#":""); // get any extra info $non_root_extra_info = str_replace("#","",substr($root_arr[1],1)); // assuming that extra info does not have any # // find the index on chords array $non_root_index = array_search($non_root,$chords); // transpose the values and modulo by 12 so we always point to existing indexes in our array $non_root_transpose_index = floor(($non_root_index + $transpose) % 12); if ($non_root_transpose_index < 0) { $non_root_transpose_index += 12; } $result.= "/".$chords[$non_root_transpose_index].$non_root_extra_info; } return $result; }

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.13
8.3.50.0140.00718.17
8.3.40.0090.00918.79
8.3.30.0100.00318.89
8.3.20.0040.00420.34
8.3.10.0060.00321.73
8.3.00.0000.00719.02
8.2.180.0150.00018.41
8.2.170.0070.00722.96
8.2.160.0100.00319.28
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00019.48
8.2.110.0030.00622.08
8.2.100.0120.00017.84
8.2.90.0000.00817.75
8.2.80.0080.00018.92
8.2.70.0040.00417.50
8.2.60.0080.00018.04
8.2.50.0040.00417.75
8.2.40.0040.00419.35
8.2.30.0000.00821.00
8.2.20.0040.00417.63
8.2.10.0040.00418.04
8.2.00.0000.00718.02
8.1.280.0120.00325.92
8.1.270.0040.00423.79
8.1.260.0030.00526.35
8.1.250.0080.00028.09
8.1.240.0060.00323.88
8.1.230.0040.00819.57
8.1.220.0000.00817.79
8.1.210.0000.00818.77
8.1.200.0030.00617.23
8.1.190.0000.00917.13
8.1.180.0080.00018.10
8.1.170.0050.00218.96
8.1.160.0050.00222.11
8.1.150.0070.00018.82
8.1.140.0070.00019.64
8.1.130.0070.00017.72
8.1.120.0080.00017.36
8.1.110.0030.00517.50
8.1.100.0040.00417.52
8.1.90.0040.00417.36
8.1.80.0000.00817.43
8.1.70.0040.00417.51
8.1.60.0000.00917.49
8.1.50.0040.00417.52
8.1.40.0030.00617.51
8.1.30.0060.00317.68
8.1.20.0030.00517.62
8.1.10.0060.00317.47
8.1.00.0030.00517.45
8.0.300.0050.00218.77
8.0.290.0040.00416.75
8.0.280.0030.00318.36
8.0.270.0040.00716.79
8.0.260.0030.00318.54
8.0.250.0000.00716.81
8.0.240.0040.00416.95
8.0.230.0020.00516.99
8.0.220.0040.00416.81
8.0.210.0030.00316.95
8.0.200.0000.00716.82
8.0.190.0000.00816.82
8.0.180.0040.00416.81
8.0.170.0000.00816.93
8.0.160.0000.00716.98
8.0.150.0020.00616.85
8.0.140.0000.00816.81
8.0.130.0050.00115.06
8.0.120.0020.00616.88
8.0.110.0010.00616.79
8.0.100.0040.00416.88
8.0.90.0050.00216.87
8.0.80.0040.01016.92
8.0.70.0030.00516.83
8.0.60.0040.00416.81
8.0.50.0060.00216.81
8.0.30.0060.00716.98
8.0.20.0080.01017.27
8.0.10.0020.00516.94
8.0.00.0130.00216.88
7.4.330.0000.00515.08
7.4.320.0000.00716.51
7.4.300.0030.00316.63
7.4.290.0000.00716.35
7.4.280.0000.00716.46
7.4.270.0030.00516.52
7.4.260.0030.00316.45
7.4.250.0000.00716.45
7.4.240.0030.00316.50
7.4.230.0040.00416.47
7.4.220.0050.00816.50
7.4.210.0090.00416.54
7.4.200.0050.00416.53
7.4.190.0040.00416.51
7.4.180.0000.00716.55
7.4.160.0060.00616.63
7.4.150.0080.00816.93
7.4.140.0060.00817.38
7.4.130.0080.00916.55
7.4.120.0050.00816.45
7.4.110.0080.00316.54
7.4.100.0050.00816.45
7.4.90.0060.00616.46
7.4.80.0100.00317.87
7.4.70.0040.01016.38
7.4.60.0030.00816.40
7.4.50.0060.00416.48
7.4.40.0060.01016.40
7.4.30.0060.00916.43
7.4.20.0070.00816.45
7.4.10.0070.01016.48
7.4.00.0080.00716.03
7.3.330.0130.00214.75
7.3.320.0120.00414.67
7.3.310.0110.00616.25
7.3.300.0120.00316.27
7.3.290.0100.00616.33
7.3.280.0110.00816.28
7.3.270.0130.00816.85
7.3.260.0090.01016.30
7.3.250.0120.00916.41
7.3.240.0150.00616.52
7.3.230.0160.00316.43
7.3.220.0220.00416.22
7.3.210.0110.00916.38
7.3.200.0160.00416.35
7.3.190.0170.00316.37
7.3.180.0140.00516.40
7.3.170.0100.00816.40
7.3.160.0070.01016.37
7.3.150.0100.00916.41
7.3.140.0080.01016.41
7.3.130.0140.00416.51
7.3.120.0120.00516.10
7.3.110.0100.00815.99
7.3.100.0090.00715.78
7.3.90.0090.00615.84
7.3.80.0110.00615.79
7.3.70.0090.00615.86
7.3.60.0070.00915.75
7.3.50.0090.00715.85
7.3.40.0090.00815.80
7.3.30.0090.00815.80
7.3.20.0130.00816.91
7.3.10.0120.00616.99
7.3.00.0110.00716.93
7.2.340.0150.00416.28
7.2.330.0100.00816.46
7.2.320.0140.00516.59
7.2.310.0130.00816.37
7.2.300.0110.00716.53
7.2.290.0060.01216.33
7.2.280.0120.00616.56
7.2.270.0120.00616.65
7.2.260.0100.00916.54
7.2.250.0070.01216.35
7.2.240.0100.00916.28
7.2.230.0100.00716.02
7.2.220.0090.00815.94
7.2.210.0110.00815.90
7.2.200.0080.00816.02
7.2.190.0080.00815.99
7.2.180.0060.01115.91
7.2.170.0100.00916.02
7.2.160.0080.00915.96
7.2.150.0100.00817.14
7.2.140.0110.00717.17
7.2.130.0120.00917.15
7.2.120.0110.00717.11
7.2.110.0120.00617.16
7.2.100.0120.00617.14
7.2.90.0360.00816.93
7.2.80.0350.00616.89
7.2.70.0260.00916.96
7.2.60.0320.00716.87
7.2.50.0440.01016.95
7.2.40.0300.00816.96
7.2.30.0280.00716.90
7.2.20.0320.00816.91
7.2.10.0270.00916.94
7.2.00.0210.00817.03
7.1.330.0150.00716.72
7.1.320.0130.00816.31
7.1.310.0130.00616.32
7.1.300.0140.00616.28
7.1.290.0130.01116.09
7.1.280.0140.00816.01
7.1.270.0120.00716.10
7.1.260.0100.00715.98
7.1.250.0110.00816.08
7.1.240.0140.00715.86
7.1.230.0120.00815.87
7.1.220.0120.00715.96
7.1.210.0440.00615.75
7.1.200.0370.00915.81
7.1.190.0300.00915.70
7.1.180.0480.00615.74
7.1.170.0420.00715.82
7.1.160.0290.00815.79
7.1.150.0300.00515.78
7.1.140.0300.00715.76
7.1.130.0240.00715.80
7.1.120.0290.00615.96
7.1.110.0270.00915.86
7.1.100.0260.00715.89
7.1.90.0250.00616.00
7.1.80.0260.00816.11
7.1.70.0200.01016.11
7.1.60.0190.01119.62
7.1.50.0220.01019.60
7.1.40.0290.00819.57
7.1.30.0230.00919.52
7.1.20.0220.00919.51
7.1.10.0170.00915.90
7.1.00.0140.01616.47
7.0.330.0120.00815.60
7.0.320.0120.00815.63
7.0.310.0480.00915.45
7.0.300.0380.00815.49
7.0.290.0290.00715.35
7.0.280.0260.00815.12
7.0.270.0230.01015.28
7.0.260.0310.00715.56
7.0.250.0250.01015.53
7.0.240.0210.00815.59
7.0.230.0210.01015.80
7.0.220.0380.00815.70
7.0.210.0170.00715.55
7.0.200.0230.00715.60
7.0.190.0240.00815.60
7.0.180.0160.00915.56
7.0.170.0240.00615.60
7.0.160.0210.00815.57
7.0.150.0190.00815.55
7.0.140.0220.00715.63
7.0.130.0150.00715.63
7.0.120.0170.00815.56
7.0.110.0180.00815.58
7.0.100.0210.00715.60
7.0.90.0200.00715.60
7.0.80.0200.00815.63
7.0.70.0230.01415.92
7.0.60.0260.01215.96
7.0.50.0270.01016.06
7.0.40.0380.01216.03
7.0.30.0290.01216.05
7.0.20.0240.01515.98
7.0.10.0230.01316.02
7.0.00.0250.01316.04
5.6.400.0140.00715.32
5.6.390.0140.00815.24
5.6.380.0100.01115.34
5.6.370.0130.00915.37
5.6.360.0140.00715.30
5.6.350.0140.00815.50
5.6.340.0100.01115.36
5.6.330.0130.00815.37
5.6.320.0140.00715.38
5.6.310.0120.00815.38
5.6.300.0100.01515.71
5.6.290.0140.01515.75
5.6.280.0090.02216.20
5.6.270.0120.01415.83
5.6.260.0130.01315.81
5.6.250.0130.01315.85
5.6.240.0130.01515.85
5.6.230.0120.01515.86
5.6.220.0180.01816.25
5.6.210.0200.01816.27
5.6.200.0200.01816.35
5.6.190.0200.01816.30
5.6.180.0220.01816.33
5.6.170.0230.01616.25
5.6.160.0220.01916.29
5.6.150.0230.01816.27
5.6.140.0220.01916.26
5.6.130.0220.02016.30
5.6.120.0140.01816.33
5.6.110.0140.02016.32
5.6.100.0180.01916.29
5.6.90.0200.01916.23
5.6.80.0240.01616.08
5.6.70.0200.01816.15
5.6.60.0210.01616.13
5.6.50.0240.01816.15
5.6.40.0200.01916.10
5.6.30.0220.01716.14
5.6.20.0210.01616.11
5.6.10.0220.01816.11
5.6.00.0220.01716.04
5.5.380.0140.01415.22
5.5.370.0110.01315.16
5.5.360.0170.01815.60
5.5.350.0170.01915.60
5.5.340.0190.01615.63
5.5.330.0200.01515.67
5.5.320.0230.01615.74
5.5.310.0190.01815.77
5.5.300.0210.02115.71
5.5.290.0210.01815.79
5.5.280.0120.01815.75
5.5.270.0210.01815.69
5.5.260.0200.01915.77
5.5.250.0200.01915.63
5.5.240.0190.01915.62
5.5.230.0210.01815.56
5.5.220.0210.01615.55
5.5.210.0200.01715.58
5.5.200.0160.02015.55
5.5.190.0210.02115.49
5.5.180.0200.01615.56
5.5.170.0140.00815.08
5.5.160.0190.01715.58
5.5.150.0230.01915.54
5.5.140.0190.01815.53
5.5.130.0220.01615.49
5.5.120.0220.01815.49
5.5.110.0200.02015.55
5.5.100.0200.02115.49
5.5.90.0210.02015.58
5.5.80.0190.02115.49
5.5.70.0220.01915.48
5.5.60.0230.01615.34
5.5.50.0200.01715.38
5.5.40.0200.01715.39
5.5.30.0220.01515.53
5.5.20.0200.01715.47
5.5.10.0170.01915.47
5.5.00.0200.01815.42

preferences:
45.97 ms | 401 KiB | 5 Q