3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Non-recurive Quicksort for an array of Person objects // adapted from http://www.algorithmist.com/index.php/Quicksort_non-recursive.php function quickSort( &$array ) { $cur = 1; $stack[1]['l'] = 0; $stack[1]['r'] = count($array)-1; do { $l = $stack[$cur]['l']; $r = $stack[$cur]['r']; $cur--; do { $i = $l; $j = $r; $tmp = $array[(int)( ($l+$r)/2 )]; // partion the array in two parts. // left from $tmp are with smaller values, // right from $tmp are with bigger ones do { while( $array[$i]->age < $tmp->age ) $i++; while( $tmp->age < $array[$j]->age ) $j--; // swap elements from the two sides if( $i <= $j) { $w = $array[$i]; $array[$i] = $array[$j]; $array[$j] = $w; $i++; $j--; } }while( $i <= $j ); if( $i < $r ) { $cur++; $stack[$cur]['l'] = $i; $stack[$cur]['r'] = $r; } $r = $j; }while( $l < $r ); }while( $cur != 0 ); } // usort() comparison function for Person objects function personSort( $a, $b ) { return $a->age == $b->age ? 0 : ( $a->age > $b->age ) ? 1 : -1; } // simple person object class Person { var $age; function __construct($age) { $this->age = $age; } } //---------test internal usort() on 15000 Person objects------ srand(1); $people=array(); for ($x=0; $x<15000; $x++) { $people[]=new Person(rand(1,100)); } $start=microtime(true); usort( $people, 'personSort' ); $total=microtime(true)-$start; echo "usort took $total\n"; //---------test custom quicksort on 15000 Person objects------ srand(1); $people=array(); for ($x=0; $x<15000; $x++) { $people[]=new Person(rand(1,100)); } $start=microtime(true); quickSort( $people ); $total=microtime(true)-$start; echo "quickSort took $total\n";

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.1.20.0230.00417.46
8.1.10.0230.01017.36
8.1.00.0150.00317.17
8.0.150.0060.00316.64
8.0.140.0120.00316.64
8.0.130.0100.00516.63
8.0.120.0100.00716.72
8.0.110.0110.00816.69
8.0.100.0110.01216.79
8.0.90.0180.00516.80
8.0.80.0170.00316.78
8.0.70.0140.00716.73
8.0.60.0160.00616.67
8.0.50.0150.00816.79
8.0.30.0150.00516.85
8.0.20.0160.00616.87
8.0.10.0140.00716.81
8.0.00.0080.00416.96
7.4.270.0170.03518.22
7.4.260.0240.02817.98
7.4.250.0170.04718.21
7.4.240.0140.04218.23
7.4.230.0220.04018.01
7.4.220.0070.04118.12
7.4.210.0110.05018.27
7.4.200.0150.03318.12
7.4.190.0110.03918.00
7.4.180.0070.04818.20
7.4.160.0120.04718.27
7.4.150.0190.04118.14
7.4.140.0140.03718.13
7.4.130.0150.04918.17
7.4.120.0090.04218.14
7.4.110.0190.04518.11
7.4.100.0160.03318.13
7.4.90.0150.03518.12
7.4.80.0040.04018.01
7.4.70.0190.04018.20
7.4.60.0070.05018.09
7.4.50.0120.03117.88
7.4.40.0060.03717.88
7.4.30.0040.04018.07
7.4.20.0100.03418.07
7.4.10.0070.03818.07
7.4.00.0110.04218.08
7.3.330.0150.05217.97
7.3.320.0130.04017.82
7.3.310.0100.05517.99
7.3.300.0130.05317.98
7.3.290.0160.03617.73
7.3.280.0220.03917.87
7.3.270.0210.03218.03
7.3.260.0200.03317.95
7.3.250.0150.03717.96
7.3.240.0260.03518.02
7.3.230.0130.04717.94
7.3.220.0240.03817.91
7.3.210.0140.04017.78
7.3.200.0170.03517.93
7.3.190.0180.03417.92
7.3.180.0190.03317.83
7.3.170.0170.04517.91
7.3.160.0140.03917.88
7.3.150.0100.05317.88
7.3.140.0120.05117.71
7.3.130.0130.03917.96
7.3.120.0110.04017.81
7.3.110.0090.04317.86
7.3.100.0170.03517.81
7.3.90.0190.03618.14
7.3.80.0090.04417.22
7.3.70.0180.03517.20
7.3.60.0140.04617.29
7.3.50.0140.04217.39
7.3.40.0140.03917.28
7.3.30.0100.04017.13
7.3.20.0210.03718.34
7.3.10.0220.03818.21
7.3.00.0200.04118.29
7.2.340.0220.03418.26
7.2.330.0220.05118.16
7.2.320.0180.04218.25
7.2.310.0240.03318.36
7.2.300.0190.03818.39
7.2.290.0130.04318.28
7.2.280.0170.04018.18
7.2.270.0160.04218.34
7.2.260.0130.04618.10
7.2.250.0160.05618.18
7.2.240.0150.04318.16
7.2.230.0110.04518.18
7.2.220.0170.04818.27
7.2.210.0130.04517.65
7.2.200.0150.04917.74
7.2.190.0120.06917.55
7.2.180.0200.04317.67
7.2.170.0150.06217.54
7.2.160.0180.05017.64
7.2.150.0170.04718.75
7.2.140.0250.05018.84
7.2.130.0240.04118.85
7.2.120.0270.06718.76
7.2.110.0250.05818.82
7.2.100.0620.04418.87
7.2.90.0210.04518.81
7.2.80.0360.05618.76
7.2.70.0200.06618.85
7.2.60.0180.04818.78
7.2.50.0180.04318.65
7.2.40.0490.05518.96
7.2.30.0220.05118.87
7.2.20.0270.07218.71
7.2.10.0280.07318.80
7.2.00.0180.04919.77
7.1.330.0200.06619.67
7.1.320.0270.05419.59
7.1.310.0190.05417.78
7.1.300.0280.04717.80
7.1.290.0530.05717.62
7.1.280.0230.05417.73
7.1.270.0240.07217.69
7.1.260.0170.05817.60
7.1.250.0210.06317.60
7.1.240.0250.06217.66
7.1.230.0190.06317.66
7.1.220.0250.05617.65
7.1.210.0260.05617.71
7.1.200.0250.06717.62
7.1.190.0190.05617.69
7.1.180.0190.05517.60
7.1.170.0230.05217.58
7.1.160.0270.05417.56
7.1.150.0190.06017.63
7.1.140.0220.06417.70
7.1.130.0150.05317.73
7.1.120.0170.05117.53
7.1.110.0130.05417.62
7.1.100.0370.06317.61
7.1.90.0260.05117.81
7.1.80.0220.05917.73
7.1.70.0140.05218.22
7.1.60.0140.04718.31
7.1.50.0240.06524.24
7.1.40.0240.04817.82
7.1.30.0290.04817.53
7.1.20.0190.06817.73
7.1.10.0730.04517.59
7.1.00.0170.07719.90
7.0.330.0230.06117.34
7.0.320.0250.04917.50
7.0.310.0220.07217.48
7.0.300.0220.04917.38
7.0.290.0240.05817.56
7.0.280.0250.06617.41
7.0.270.0190.05017.51
7.0.260.0240.05417.51
7.0.250.0220.05817.63
7.0.240.0170.06317.35
7.0.230.0250.05317.53
7.0.220.0220.06217.46
7.0.210.0240.06117.53
7.0.200.0190.05217.94
7.0.190.0210.05717.58
7.0.180.0260.06817.25
7.0.170.0240.06517.45
7.0.160.0220.06017.46
7.0.150.0180.05417.46
7.0.140.0160.06519.81
7.0.130.0210.04817.53
7.0.120.0230.04817.60
7.0.110.0220.06317.32
7.0.100.0220.05017.32
7.0.90.0190.06017.39
7.0.80.0160.06317.55
7.0.70.0220.05517.36
7.0.60.0240.07518.94
7.0.50.0210.08718.17
7.0.40.0140.09017.77
7.0.30.0260.07817.68
7.0.20.0240.07217.78
7.0.10.0190.07217.74
7.0.00.0180.06617.62
5.6.400.0150.21021.83
5.6.390.0120.26621.80
5.6.380.0150.18621.78
5.6.370.0220.25621.77
5.6.360.0150.21521.69
5.6.350.0150.21021.66
5.6.340.0130.22121.79
5.6.330.0130.20921.77
5.6.320.0180.17321.62
5.6.310.0170.18121.69
5.6.300.0200.19921.71
5.6.290.0110.18321.74
5.6.280.0160.19823.67
5.6.270.0200.18821.73
5.6.260.0170.21721.79
5.6.250.0180.19021.89
5.6.240.0130.21221.76
5.6.230.0210.23121.90
5.6.220.0200.20821.73
5.6.210.0300.21523.54
5.6.200.0250.25023.80
5.6.190.0180.19123.80
5.6.180.0220.19623.82
5.6.170.0210.19223.86
5.6.160.0210.20623.71
5.6.150.0220.19023.73
5.6.140.0230.17923.73
5.6.130.0210.20023.59
5.6.120.0200.19623.77
5.6.110.0180.18923.74
5.6.100.0160.19223.63
5.6.90.0180.17523.69
5.6.80.0190.18523.36
5.6.70.0130.17223.50
5.6.60.0210.21123.52
5.6.50.0260.17823.41
5.6.40.0180.18823.55
5.6.30.0180.17623.57
5.6.20.0120.18323.41
5.6.10.0210.20823.47
5.6.00.0200.20623.37
5.5.380.0180.21521.91
5.5.370.0200.21121.99
5.5.360.0250.24221.82
5.5.350.0190.22123.44
5.5.340.0240.20123.52
5.5.330.0200.20023.63
5.5.320.0170.21223.50
5.5.310.0210.17823.52
5.5.300.0230.19323.64
5.5.290.0210.19923.54
5.5.280.0160.18923.77
5.5.270.0180.23223.49
5.5.260.0150.19523.61
5.5.250.0120.19523.53
5.5.240.0140.18423.40
5.5.230.0200.19123.25
5.5.220.0200.20823.36
5.5.210.0220.18123.40
5.5.200.0190.17923.26
5.5.190.0210.18223.43
5.5.180.0230.18223.34
5.5.170.0150.18821.72
5.5.160.0220.20623.29
5.5.150.0210.20623.34
5.5.140.0170.22423.33
5.5.130.0240.22223.43
5.5.120.0190.20423.33
5.5.110.0290.22523.34
5.5.100.0210.20823.34
5.5.90.0240.20723.39
5.5.80.0200.21923.35
5.5.70.0190.21023.31
5.5.60.0190.22323.19
5.5.50.0150.24523.37
5.5.40.0200.21623.40
5.5.30.0160.20923.27
5.5.20.0270.20323.39
5.5.10.0190.20723.20
5.5.00.0170.22423.33
5.4.450.0210.19821.01
5.4.440.0180.17520.98
5.4.430.0130.21420.89
5.4.420.0140.20221.07
5.4.410.0160.18521.04
5.4.400.0110.18820.82
5.4.390.0160.17120.75
5.4.380.0190.19320.73
5.4.370.0170.19220.91
5.4.360.0230.16820.86
5.4.350.0210.18620.68
5.4.340.0200.19820.72
5.4.330.0180.17018.49
5.4.320.0190.19220.80
5.4.310.0200.22320.88
5.4.300.0270.19820.72
5.4.290.0210.18320.79
5.4.280.0140.20120.95
5.4.270.0240.21220.79
5.4.260.0190.24620.84
5.4.250.0190.20920.79
5.4.240.0180.19520.84
5.4.230.0160.21120.67
5.4.220.0190.21220.75
5.4.210.0200.20420.74
5.4.200.0140.22920.79
5.4.190.0180.19620.77
5.4.180.0220.21020.82
5.4.170.0190.21220.72
5.4.160.0190.22620.79
5.4.150.0200.20420.87
5.4.140.0140.19819.83
5.4.130.0110.24219.89
5.4.120.0130.19119.91
5.4.110.0170.23919.98
5.4.100.0110.21719.96
5.4.90.0150.20420.07
5.4.80.0180.19119.90
5.4.70.0220.21420.02
5.4.60.0190.19820.05
5.4.50.0210.20419.93
5.4.40.0190.23219.93
5.4.30.0170.22820.12
5.4.20.0110.18820.03
5.4.10.0230.23319.97
5.4.00.0200.16319.71

preferences:
42.5 ms | 401 KiB | 5 Q