3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array(8,4,1,9,5,7,3,2,6,0); /** * ############################################################################ * The nitty gritty */ // This is it! Get the data to process, split it into halfs and compare // Returns: freshly sorted, reassembled array from split array-parts function mergesort($data) { // Only process if we're not down to one piece of data if(count($data)>1) { // Find out the middle of the current data set and split it there to obtain to halfs $data_middle = round(count($data)/2, 0, PHP_ROUND_HALF_DOWN); // and now for some recursive magic $data_part1 = mergesort(array_slice($data, 0, $data_middle)); $data_part2 = mergesort(array_slice($data, $data_middle, count($data))); // Setup counters so we can remember which piece of data in each half we're looking at $counter1 = $counter2 = 0; // iterate over all pieces of the currently processed array, compare size & reassemble for ($i=0; $i<count($data); $i++) { // if we're done processing one half, take the rest from the 2nd half if($counter1 == count($data_part1)) { $data[$i] = $data_part2[$counter2]; ++$counter2; // if we're done with the 2nd half as well or as long as pieces in the first half are still smaller than the 2nd half } elseif (($counter2 == count($data_part2)) or ($data_part1[$counter1] < $data_part2[$counter2])) { $data[$i] = $data_part1[$counter1]; ++$counter1; } else { $data[$i] = $data_part2[$counter2]; ++$counter2; } } } return $data; } // Initiate the recursive magic by calling the function once & print the output for our viewing pleasure $data = mergesort($data); print_r($data); ?>

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.0110.00418.43
8.3.50.0140.00418.09
8.3.40.0150.00018.92
8.3.30.0100.00318.88
8.3.20.0030.00520.46
8.3.10.0040.00421.80
8.3.00.0080.00019.14
8.2.180.0090.00616.75
8.2.170.0040.01122.96
8.2.160.0040.01119.29
8.2.150.0050.00324.18
8.2.140.0000.00824.66
8.2.130.0050.00220.52
8.2.120.0070.00026.35
8.2.110.0090.00019.26
8.2.100.0080.00318.03
8.2.90.0050.00517.97
8.2.80.0000.01017.97
8.2.70.0000.00917.62
8.2.60.0050.00318.16
8.2.50.0030.00918.10
8.2.40.0030.00522.25
8.2.30.0030.00619.45
8.2.20.0040.00417.81
8.2.10.0000.00718.07
8.2.00.0040.00418.07
8.1.280.0170.00325.92
8.1.270.0040.00421.96
8.1.260.0000.00828.09
8.1.250.0040.00428.09
8.1.240.0030.00622.68
8.1.230.0080.00320.92
8.1.220.0000.00817.91
8.1.210.0000.00818.91
8.1.200.0060.00317.47
8.1.190.0000.00817.23
8.1.180.0080.00018.10
8.1.170.0040.00418.69
8.1.160.0040.00422.09
8.1.150.0070.00018.84
8.1.140.0040.00419.65
8.1.130.0060.00317.69
8.1.120.0070.00017.57
8.1.110.0000.00917.42
8.1.100.0000.00717.48
8.1.90.0030.00517.43
8.1.80.0000.00717.58
8.1.70.0000.00717.50
8.1.60.0060.00317.66
8.1.50.0000.00817.66
8.1.40.0040.00417.52
8.1.30.0000.00817.56
8.1.20.0040.00417.63
8.1.10.0040.00417.51
8.1.00.0000.00817.57
8.0.300.0000.00820.07
8.0.290.0040.00416.75
8.0.280.0000.00718.47
8.0.270.0000.00717.28
8.0.260.0030.00317.20
8.0.250.0000.00716.91
8.0.240.0040.00417.05
8.0.230.0040.00416.96
8.0.220.0050.00216.84
8.0.210.0050.00316.99
8.0.200.0050.00516.99
8.0.190.0040.00417.04
8.0.180.0060.00316.91
8.0.170.0020.00516.85
8.0.160.0070.00017.02
8.0.150.0040.00416.89
8.0.140.0060.00316.96
8.0.130.0000.00613.35
8.0.120.0040.00416.87
8.0.110.0040.00416.96
8.0.100.0000.00816.74
8.0.90.0020.00516.83
8.0.80.0110.00316.87
8.0.70.0040.00416.77
8.0.60.0080.00017.03
8.0.50.0000.00716.78
8.0.30.0030.01717.05
8.0.20.0110.01017.40
8.0.10.0080.00016.95
8.0.00.0090.00917.02
7.4.330.0050.00015.08
7.4.320.0060.00016.44
7.4.300.0000.00816.68
7.4.290.0080.00016.71
7.4.280.0040.00416.46
7.4.270.0030.00416.64
7.4.260.0030.00316.63
7.4.250.0000.00816.52
7.4.240.0050.00216.60
7.4.230.0000.00616.49
7.4.220.0150.01116.58
7.4.210.0070.00916.66
7.4.200.0040.00416.44
7.4.160.0120.00316.63
7.4.150.0110.00617.40
7.4.140.0140.00917.86
7.4.130.0130.00416.58
7.4.120.0070.01216.60
7.4.110.0110.00716.47
7.4.100.0030.01316.39
7.4.90.0030.01516.46
7.4.80.0140.00319.39
7.4.70.0100.00616.55
7.4.60.0080.00816.63
7.4.50.0030.01016.36
7.4.40.0030.01316.41
7.4.30.0070.01016.37
7.4.10.0070.01015.02
7.4.00.0070.01014.96
7.3.330.0000.00513.41
7.3.320.0030.00313.30
7.3.310.0080.00016.48
7.3.300.0030.00316.45
7.3.290.0000.00616.38
7.3.280.0070.01116.42
7.3.270.0140.01017.40
7.3.260.0130.01016.73
7.3.250.0120.00816.44
7.3.240.0070.01016.54
7.3.230.0070.01016.66
7.3.210.0140.00716.46
7.3.200.0140.01019.39
7.3.190.0100.00616.42
7.3.180.0160.00616.42
7.3.170.0030.01516.70
7.3.160.0120.00916.35
7.3.130.0040.01114.76
7.3.120.0040.01214.94
7.3.110.0070.00814.94
7.3.100.0060.01014.94
7.3.90.0060.00814.84
7.3.80.0050.00814.94
7.3.70.0040.01014.76
7.3.60.0080.00814.86
7.3.50.0070.00714.77
7.3.40.0060.00814.79
7.3.30.0040.00914.76
7.3.20.0040.01016.81
7.3.10.0060.01116.71
7.3.00.0070.00716.55
7.2.330.0100.00716.94
7.2.320.0070.01817.02
7.2.310.0000.01716.75
7.2.300.0090.00916.50
7.2.290.0030.01516.51
7.2.260.0060.01215.29
7.2.250.0050.01315.01
7.2.240.0060.01015.12
7.2.230.0060.01015.04
7.2.220.0060.00814.97
7.2.210.0070.00915.18
7.2.200.0080.00614.98
7.2.190.0040.00814.99
7.2.180.0050.00615.05
7.2.170.0050.00814.99
7.2.160.0060.00914.77
7.2.150.0070.00717.01
7.2.140.0060.00916.65
7.2.130.0050.01016.87
7.2.120.0050.00816.88
7.2.110.0030.01016.95
7.2.100.0060.00516.85
7.2.90.0030.01317.11
7.2.80.0030.01217.00
7.2.70.0060.00917.14
7.2.60.0050.01016.88
7.2.50.0090.00616.93
7.2.40.0130.00317.02
7.2.30.0060.00817.04
7.2.20.0040.01216.87
7.2.10.0080.00717.00
7.2.00.0070.00616.88
7.1.330.0050.01015.91
7.1.320.0060.00715.87
7.1.310.0050.00715.79
7.1.300.0050.00915.72
7.1.290.0050.00615.90
7.1.280.0040.01015.69
7.1.270.0060.00815.76
7.1.260.0040.00915.79
7.1.250.0080.00615.89
7.1.240.0080.00515.75
7.1.230.0050.00715.82
7.1.220.0070.00515.80
7.1.210.0070.00615.69
7.1.200.0090.00515.72
7.1.190.0060.00615.89
7.1.180.0100.00515.89
7.1.170.0020.01115.83
7.1.160.0030.00815.81
7.1.150.0030.00915.77
7.1.140.0090.00515.93
7.1.130.0060.00815.70
7.1.120.0110.00515.88
7.1.110.0140.00215.73
7.1.100.0050.01015.81
7.1.90.0070.00915.77
7.1.80.0030.00915.86
7.1.70.0070.00516.40
7.1.60.0030.00917.24
7.1.50.0020.01115.71
7.1.40.0100.00415.79
7.1.30.0030.00915.78
7.1.20.0020.00815.67
7.1.10.0080.00715.81
7.1.00.0040.03018.04
7.0.330.0070.00715.39
7.0.320.0080.00515.35
7.0.310.0030.00815.31
7.0.300.0040.00415.41
7.0.290.0060.00715.28
7.0.280.0080.00515.22
7.0.270.0070.00515.32
7.0.260.0080.00415.48
7.0.250.0040.00915.48
7.0.240.0080.00415.35
7.0.230.0000.01415.44
7.0.220.0060.00615.22
7.0.210.0050.00715.55
7.0.200.0170.00415.14
7.0.190.0030.01415.35
7.0.180.0030.01015.46
7.0.170.0030.00915.47
7.0.160.0090.00415.41
7.0.150.0050.00715.39
7.0.140.0100.00315.40
7.0.130.0100.00315.32
7.0.120.0110.00215.54
7.0.110.0000.01515.46
7.0.100.0060.00815.35
7.0.90.0040.00915.49
7.0.80.0090.02316.83
7.0.70.0090.02417.01
7.0.60.0170.02416.91
7.0.50.0230.01917.08
7.0.40.0230.02115.73
7.0.30.0170.02615.78
7.0.20.0190.02215.73
7.0.10.0240.02015.83
7.0.00.0240.02215.77
5.6.400.0030.01014.16
5.6.390.0130.00314.68
5.6.380.0100.00414.39
5.6.370.0080.00714.56
5.6.360.0070.01014.28
5.6.350.0000.01114.34
5.6.340.0080.00714.20
5.6.330.0030.01314.47
5.6.320.0090.00314.34
5.6.310.0070.00314.37
5.6.300.0030.00914.31
5.6.290.0050.00713.97
5.6.280.0050.03116.73
5.6.270.0030.01114.47
5.6.260.0060.00914.33
5.6.250.0050.00514.57
5.6.240.0030.01114.38
5.6.230.0050.00814.38
5.6.220.0190.02316.54
5.6.210.0150.02416.47
5.6.200.0170.02416.67
5.6.190.0200.02216.66
5.6.180.0140.02516.62
5.6.170.0180.02316.59
5.6.160.0200.02416.55
5.6.150.0210.02316.59
5.6.140.0180.02316.69
5.6.130.0130.02816.70
5.6.120.0090.02616.70
5.6.110.0100.02616.58
5.6.100.0200.02216.56
5.6.90.0170.02516.72
5.6.80.0210.01916.34
5.6.70.0180.02416.31
5.6.60.0190.02116.41
5.6.50.0160.02316.48
5.6.40.0210.02216.31
5.6.30.0170.02116.43
5.6.20.0230.02216.33
5.6.10.0230.03016.42
5.6.00.0130.02316.23
5.5.380.0040.01012.94
5.5.370.0100.00212.94
5.5.360.0180.02415.48
5.5.350.0130.02915.52
5.5.340.0230.02615.64
5.5.330.0170.02315.59
5.5.320.0160.02515.62
5.5.310.0220.02015.59
5.5.300.0100.02815.58
5.5.290.0170.02815.63
5.5.280.0050.02815.61
5.5.270.0120.02815.67
5.5.260.0160.02415.70
5.5.250.0180.02215.65
5.5.240.0160.02615.42
5.5.230.0120.02915.42
5.5.220.0180.02115.29
5.5.210.0160.02815.34
5.5.200.0140.02415.24
5.5.190.0140.02415.49
5.5.180.0140.02315.42
5.5.170.0060.00612.95
5.5.160.0230.02715.35
5.5.150.0200.01915.33
5.5.140.0150.02515.52
5.5.130.0150.02515.47
5.5.120.0190.02015.43
5.5.110.0220.01915.38
5.5.100.0210.02015.37
5.5.90.0140.02415.29
5.5.80.0180.02015.26
5.5.70.0180.02315.31
5.5.60.0200.02815.44
5.5.50.0170.02415.38
5.5.40.0200.01915.37
5.5.30.0170.02115.36
5.5.20.0230.02315.40
5.5.10.0160.02215.38
5.5.00.0160.02115.19

preferences:
61.99 ms | 400 KiB | 5 Q