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.4.100.0170.00619.57
8.4.90.0300.00917.61
8.4.80.0380.00917.57
8.4.70.0400.01117.54
8.4.60.0440.00717.59
8.4.50.0290.00417.83
8.4.40.0240.00217.42
8.4.30.0350.00517.14
8.4.20.0370.00417.30
8.4.10.0210.00617.37
8.3.230.0410.00816.40
8.3.220.0180.00416.69
8.3.210.0180.00416.53
8.3.200.0190.00316.56
8.3.190.0350.00916.38
8.3.180.0380.00816.77
8.3.170.0400.01416.48
8.3.160.0280.00616.45
8.3.150.0280.00416.72
8.3.140.0340.00816.66
8.3.130.0170.00416.73
8.3.120.0280.00516.63
8.3.110.0320.01116.69
8.3.100.0300.00816.50
8.3.90.0380.00716.56
8.3.80.0440.00616.61
8.3.70.0430.00716.52
8.3.60.0290.00516.46
8.3.50.0210.00216.52
8.3.40.0420.00717.42
8.3.30.0290.00817.31
8.3.20.0280.01017.38
8.3.10.0310.00917.48
8.3.00.0200.00817.36
8.2.290.0310.01116.64
8.2.280.0300.01216.22
8.2.270.0260.00816.44
8.2.260.0270.01016.47
8.2.250.0440.00616.48
8.2.240.0300.01416.72
8.2.230.0350.00516.24
8.2.220.0360.00916.70
8.2.210.0250.01016.14
8.2.200.0320.00716.53
8.2.190.0400.00516.57
8.2.180.0310.01016.23
8.2.170.0360.00717.48
8.2.160.0340.01017.39
8.2.150.0340.01117.45
8.2.140.0360.00917.40
8.2.130.0260.00417.30
8.2.120.0170.00317.59
8.2.110.0150.00917.38
8.2.100.0150.00517.56
8.2.90.0160.00317.30
8.2.80.0280.00717.15
8.2.70.0150.00617.27
8.2.60.0200.00317.50
8.2.50.0310.01017.48
8.2.40.0340.00717.33
8.2.30.0270.00517.41
8.2.20.0320.00817.46
8.2.10.0260.01217.24
8.2.00.0230.00317.39
8.1.330.0250.00515.97
8.1.320.0280.01115.92
8.1.310.0330.00816.16
8.1.300.0340.00815.81
8.1.290.0340.01216.07
8.1.280.0310.01016.07
8.1.270.0320.00916.89
8.1.260.0280.01117.14
8.1.250.0300.00917.20
8.1.240.0320.00917.14
8.1.230.0300.00816.97
8.1.220.0280.00617.16
8.1.210.0120.00517.09
8.1.200.0200.00317.01
8.1.190.0290.00817.08
8.1.180.0200.00217.09
8.1.170.0210.00617.18
8.1.160.0310.00717.11
8.1.150.0280.01116.95
8.1.140.0290.00817.28
8.1.130.0210.00317.25
8.1.120.0140.00517.34
8.1.110.0320.00617.01
8.1.100.0260.00517.26
8.1.90.0180.00917.07
8.1.80.0150.00217.23
8.1.70.0230.00617.12
8.1.60.0340.00517.21
8.1.50.0360.01017.30
8.1.40.0300.00816.97
8.1.30.0320.00717.47
8.1.20.0310.00917.35
8.1.10.0280.00817.25
8.1.00.0220.00617.15
8.0.300.0310.01116.37
8.0.290.0310.00616.32
8.0.280.0250.00316.45
8.0.270.0270.00716.45
8.0.260.0340.00516.21
8.0.250.0310.00616.59
8.0.240.0290.00716.70
8.0.230.0310.00916.57
8.0.220.0310.00616.41
8.0.210.0250.01116.49
8.0.200.0290.00716.46
8.0.190.0280.01016.38
8.0.180.0290.00816.41
8.0.170.0320.00616.63
8.0.160.0340.00216.41
8.0.150.0120.00416.56
8.0.140.0170.00416.50
8.0.130.0210.00516.51
8.0.120.0190.00916.64
8.0.110.0190.00916.55
8.0.100.0210.00816.68
8.0.90.0260.00416.56
8.0.80.0260.00416.65
8.0.70.0200.00716.67
8.0.60.0220.00816.58
8.0.50.0240.00616.65
8.0.30.0250.00716.70
8.0.20.0200.00616.74
8.0.10.0200.00716.65
8.0.00.0200.00316.77
7.4.330.0330.03318.26
7.4.320.0200.03517.98
7.4.300.0180.02818.03
7.4.290.0280.02318.06
7.4.280.0200.03217.93
7.4.270.0270.03018.27
7.4.260.0180.02518.05
7.4.250.0240.03818.18
7.4.240.0200.03618.17
7.4.230.0270.03718.09
7.4.220.0120.03118.16
7.4.210.0150.04318.24
7.4.200.0160.03118.11
7.4.190.0170.03418.09
7.4.180.0130.04318.18
7.4.160.0150.04018.19
7.4.150.0250.03618.19
7.4.140.0180.03518.13
7.4.130.0160.03118.19
7.4.120.0110.03018.02
7.4.110.0170.03218.06
7.4.100.0140.02618.14
7.4.90.0120.02818.08
7.4.80.0090.02918.13
7.4.70.0150.03018.21
7.4.60.0120.03317.98
7.4.50.0220.03017.97
7.4.40.0200.03017.92
7.4.30.0150.04018.04
7.4.20.0240.03517.96
7.4.10.0180.03518.06
7.4.00.0210.03518.04
7.3.330.0180.04017.88
7.3.320.0200.03617.85
7.3.310.0150.04417.97
7.3.300.0200.04217.88
7.3.290.0220.03317.77
7.3.280.0190.02917.96
7.3.270.0180.02618.02
7.3.260.0170.02617.98
7.3.250.0140.02917.96
7.3.240.0210.02618.12
7.3.230.0130.03318.02
7.3.220.0280.03417.96
7.3.210.0130.03017.93
7.3.200.0160.02617.99
7.3.190.0230.03217.97
7.3.180.0250.03217.95
7.3.170.0190.04417.81
7.3.160.0220.03417.94
7.3.150.0200.04517.82
7.3.140.0120.03517.84
7.3.130.0120.03017.98
7.3.120.0150.03817.89
7.3.110.0200.03617.83
7.3.100.0200.03617.81
7.3.90.0170.02918.21
7.3.80.0160.04217.48
7.3.70.0150.03317.47
7.3.60.0140.03617.59
7.3.50.0160.03917.66
7.3.40.0180.03617.46
7.3.30.0160.03817.43
7.3.20.0250.03518.87
7.3.10.0180.03218.80
7.3.00.0200.04018.77
7.2.340.0170.02818.20
7.2.330.0250.03518.19
7.2.320.0180.03218.32
7.2.310.0270.03218.26
7.2.300.0170.03018.29
7.2.290.0240.03818.22
7.2.280.0240.03318.18
7.2.270.0180.03918.24
7.2.260.0180.03818.13
7.2.250.0170.05318.16
7.2.240.0230.03718.24
7.2.230.0110.03518.29
7.2.220.0210.04318.29
7.2.210.0150.03617.81
7.2.200.0190.04417.99
7.2.190.0130.05317.82
7.2.180.0190.03517.94
7.2.170.0150.04917.88
7.2.160.0220.04517.87
7.2.150.0170.03819.30
7.2.140.0220.04719.29
7.2.130.0210.03419.40
7.2.120.0220.05319.28
7.2.110.0270.05419.39
7.2.100.0510.03619.35
7.2.90.0220.04219.40
7.2.80.0330.05119.33
7.2.70.0210.05219.40
7.2.60.0210.04619.30
7.2.50.0180.04219.24
7.2.40.0450.04619.45
7.2.30.0240.04619.40
7.2.20.0270.05819.34
7.2.10.0240.06019.37
7.2.00.0160.04319.99
7.1.330.0170.05219.40
7.1.320.0250.04119.51
7.1.310.0220.04818.32
7.1.300.0230.04118.33
7.1.290.0450.05018.20
7.1.280.0240.05118.22
7.1.270.0270.05618.21
7.1.260.0190.05218.21
7.1.250.0220.05118.15
7.1.240.0240.05518.23
7.1.230.0220.05318.18
7.1.220.0220.04418.20
7.1.210.0220.04518.25
7.1.200.0210.05218.16
7.1.190.0160.04618.25
7.1.180.0210.05218.17
7.1.170.0190.04218.13
7.1.160.0220.04418.13
7.1.150.0200.05418.12
7.1.140.0230.05418.25
7.1.130.0200.04618.23
7.1.120.0190.04718.06
7.1.110.0140.04418.18
7.1.100.0330.05518.13
7.1.90.0260.04518.32
7.1.80.0190.04718.25
7.1.70.0130.04518.47
7.1.60.0180.04418.53
7.1.50.0230.05723.00
7.1.40.0200.03918.28
7.1.30.0230.03918.15
7.1.20.0200.05918.22
7.1.10.0570.04218.17
7.1.00.0160.06619.77
7.0.330.0210.04817.93
7.0.320.0250.04517.95
7.0.310.0180.05617.97
7.0.300.0240.04617.88
7.0.290.0250.05218.03
7.0.280.0210.05317.89
7.0.270.0160.04317.97
7.0.260.0200.04318.06
7.0.250.0230.04818.12
7.0.240.0170.05417.92
7.0.230.0230.05318.05
7.0.220.0230.05717.95
7.0.210.0230.04918.08
7.0.200.0180.04418.26
7.0.190.0220.05618.04
7.0.180.0220.05417.86
7.0.170.0200.05118.07
7.0.160.0180.04817.98
7.0.150.0200.04817.94
7.0.140.0170.05619.63
7.0.130.0200.04218.06
7.0.120.0250.04718.11
7.0.110.0190.04917.84
7.0.100.0190.04117.92
7.0.90.0210.05317.90
7.0.80.0180.05118.03
7.0.70.0190.04417.95
7.0.60.0250.06518.97
7.0.50.0200.07617.84
7.0.40.0180.07617.59
7.0.30.0230.06417.58
7.0.20.0210.06017.63
7.0.10.0180.06517.59
7.0.00.0190.05717.47
5.6.400.0180.16922.02
5.6.390.0170.20522.02
5.6.380.0140.14821.98
5.6.370.0220.19521.98
5.6.360.0140.16821.94
5.6.350.0190.16921.91
5.6.340.0200.17422.02
5.6.330.0140.16321.96
5.6.320.0190.13921.83
5.6.310.0200.14321.93
5.6.300.0220.16621.86
5.6.290.0130.14621.98
5.6.280.0170.17223.31
5.6.270.0230.15421.97
5.6.260.0190.16721.93
5.6.250.0230.15522.09
5.6.240.0150.16521.99
5.6.230.0240.17622.02
5.6.220.0190.16321.96
5.6.210.0280.17823.25
5.6.200.0260.20823.46
5.6.190.0200.16023.45
5.6.180.0190.16623.41
5.6.170.0210.16023.47
5.6.160.0200.17223.41
5.6.150.0210.15923.42
5.6.140.0250.15423.40
5.6.130.0230.17123.28
5.6.120.0180.16523.44
5.6.110.0170.16323.31
5.6.100.0160.16623.19
5.6.90.0190.14823.29
5.6.80.0220.16023.15
5.6.70.0170.14923.19
5.6.60.0210.17923.17
5.6.50.0230.15023.13
5.6.40.0180.16323.19
5.6.30.0200.15323.29
5.6.20.0130.15423.10
5.6.10.0190.17423.17
5.6.00.0190.17223.09
5.5.380.0230.17022.11
5.5.370.0230.16922.22
5.5.360.0230.18422.07
5.5.350.0210.18723.18
5.5.340.0220.16923.23
5.5.330.0220.17123.27
5.5.320.0180.17823.16
5.5.310.0220.15223.15
5.5.300.0210.16423.33
5.5.290.0220.17123.25
5.5.280.0190.16223.42
5.5.270.0170.19323.18
5.5.260.0140.16523.28
5.5.250.0140.16423.20
5.5.240.0180.16023.11
5.5.230.0210.16223.06
5.5.220.0220.17723.12
5.5.210.0220.15323.09
5.5.200.0180.15223.05
5.5.190.0240.15723.15
5.5.180.0210.15523.10
5.5.170.0200.15321.91
5.5.160.0200.17423.09
5.5.150.0210.17723.01
5.5.140.0160.18723.05
5.5.130.0220.18523.09
5.5.120.0180.17223.03
5.5.110.0250.18623.07
5.5.100.0220.18023.10
5.5.90.0260.17423.16
5.5.80.0210.18823.03
5.5.70.0200.17823.15
5.5.60.0180.19122.94
5.5.50.0180.20423.07
5.5.40.0190.18123.10
5.5.30.0180.17823.00
5.5.20.0270.18023.14
5.5.10.0220.17622.92
5.5.00.0170.18723.03
5.4.450.0180.16820.56
5.4.440.0160.14920.50
5.4.430.0130.17920.45
5.4.420.0170.17320.63
5.4.410.0150.15720.55
5.4.400.0120.17220.36
5.4.390.0150.14620.33
5.4.380.0170.16320.30
5.4.370.0200.16420.50
5.4.360.0210.14420.42
5.4.350.0200.15720.30
5.4.340.0180.16720.33
5.4.330.0160.13818.73
5.4.320.0210.17020.38
5.4.310.0170.18620.45
5.4.300.0240.16820.30
5.4.290.0190.15520.38
5.4.280.0130.16920.52
5.4.270.0220.17620.39
5.4.260.0200.20620.41
5.4.250.0200.17920.36
5.4.240.0170.16420.46
5.4.230.0160.18220.17
5.4.220.0200.18020.30
5.4.210.0180.17120.33
5.4.200.0140.19120.34
5.4.190.0160.16820.30
5.4.180.0200.17620.35
5.4.170.0210.18120.27
5.4.160.0170.18820.38
5.4.150.0180.17220.38
5.4.140.0150.17019.65
5.4.130.0120.20319.70
5.4.120.0130.16119.77
5.4.110.0180.20219.82
5.4.100.0150.18219.78
5.4.90.0140.17219.83
5.4.80.0170.16119.75
5.4.70.0200.17819.79
5.4.60.0200.17019.83
5.4.50.0190.17119.71
5.4.40.0200.19519.77
5.4.30.0160.18819.90
5.4.20.0110.15919.82
5.4.10.0230.19619.77
5.4.00.0170.14119.55

preferences:
29.19 ms | 403 KiB | 5 Q