3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Exercise_One; /** * Zillow exercise one * * Take an associative array and sort it based on columns and directions specified. (PSR1 Standard) * * @author Joe Rocha <joe.rocha@me.com> */ class Singleton { /** * @var Singleton The reference to *Singleton* instance of this class */ protected static $instance; /** * Returns sorted multidimensional, associative array * * @param array $array Data to sort. * @param string $sortKey Key to sort by. * @param string $dir Direction to sort ('ASC' || 'DESC'). * @param bool $nat Natural sorting. * * @return bool $instance True if no other instance. */ public static function sortBy( array &$array, $sortKey = null, $dir = 'ASC', $nat = false ) { if ( null === static::$instance ) { static::$instance = new static(); }; function sortLogic( $key, $dir, $nat ) { return function( $a, $b ) use ( $key, $dir, $nat ) { if ( true === $nat ){ return strnatcmp( 'ASC' === $dir ? $a : $b [ $key ], 'ASC' === $dir ? $b : $a [ $key ] ); } else { return $dir === 'ASC' ? $a[$key] > $b[$key] : $a[$key] < $b[$key]; } }; } uasort( $array, sortLogic( $sortKey, $dir, $nat ) ); return static::$instance; } /** * Make constructor private, so no one can call "new Class". */ private function __construct() {} /** * Make clone magic method private, so no one can clone instance. */ private function __clone() {} /** * Make sleep magic method private, so no one can serialize instance. */ private function __sleep() {} /** * Make wakeup magic method private, so no one can unserialize instance. */ private function __wakeup() {} } // Dummy Data for testing $data = array(); $data[] = array('id' => 1, 'number' => '1', 'street' => 'Battery St', 'unit' => '1', 'rent' => 1200); $data[] = array('id' => 10, 'number' => '10', 'street' => 'Battery St', 'unit' => '3', 'rent' => 1800); $data[] = array('id' => 2, 'number' => '2', 'street' => 'Leavenworth St', 'unit' => '11', 'rent' => 800); $data[] = array('id' => 12, 'number' => '12', 'street' => 'Battery St', 'unit' => '10', 'rent' => 3400); $data[] = array('id' => 1, 'number' => '14', 'street' => 'Leavenworth St', 'unit' => '10', 'rent' => 1450); $data[] = array('id' => 1, 'number' => '01', 'street' => 'Battery St', 'unit' => '5', 'rent' => 1000); // Sanity check Singleton::sortBy( $data, 'number', 'DESC', true ); 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.00716.75
8.3.50.0070.01016.52
8.3.40.0040.01118.85
8.3.30.0070.00718.96
8.3.20.0040.00420.34
8.3.10.0060.00323.47
8.3.00.0040.00422.02
8.2.180.0140.00718.16
8.2.170.0060.01222.96
8.2.160.0110.00419.05
8.2.150.0040.00424.18
8.2.140.0070.00024.66
8.2.130.0050.00219.27
8.2.120.0040.00426.35
8.2.110.0120.00620.93
8.2.100.0040.00818.21
8.2.90.0040.00419.40
8.2.80.0000.00817.97
8.2.70.0100.00217.25
8.2.60.0000.00818.03
8.2.50.0000.00818.10
8.2.40.0000.00720.30
8.2.30.0080.00021.02
8.2.20.0030.00618.08
8.2.10.0030.00618.04
8.2.00.0070.00018.03
8.1.280.0070.01525.92
8.1.270.0040.00422.18
8.1.260.0070.00026.35
8.1.250.0060.00328.09
8.1.240.0090.00023.98
8.1.230.0040.00717.77
8.1.220.0040.00417.80
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0060.00317.23
8.1.180.0000.00818.10
8.1.170.0060.00318.64
8.1.160.0000.00719.03
8.1.150.0030.00618.82
8.1.140.0000.00819.65
8.1.130.0050.00318.80
8.1.120.0070.00017.39
8.1.110.0080.00017.42
8.1.100.0000.00717.52
8.1.90.0000.00817.40
8.1.80.0000.00817.37
8.1.70.0070.00017.41
8.1.60.0040.00417.50
8.1.50.0040.00417.55
8.1.40.0050.00317.53
8.1.30.0000.00917.55
8.1.20.0050.00217.68
8.1.10.0000.00917.52
8.1.00.0000.00817.62
8.0.300.0080.00018.77
8.0.290.0000.00816.59
8.0.280.0000.00818.38
8.0.270.0040.00417.29
8.0.260.0030.00316.98
8.0.250.0000.00816.92
8.0.240.0060.00317.08
8.0.230.0000.00917.02
8.0.220.0030.00317.04
8.0.210.0030.00316.97
8.0.200.0030.00316.90
8.0.190.0080.00016.93
8.0.180.0040.00416.98
8.0.170.0050.00317.01
8.0.160.0000.00717.03
8.0.150.0000.00716.95
8.0.140.0000.00716.80
8.0.130.0060.00013.41
8.0.120.0000.00816.92
8.0.110.0000.00716.94
8.0.100.0020.00517.05
8.0.90.0020.00516.79
8.0.80.0100.01016.88
8.0.70.0040.00416.96
8.0.60.0080.00016.88
8.0.50.0000.00716.80
8.0.30.0130.00317.22
8.0.20.0110.01017.41
8.0.10.0000.00717.02
8.0.00.0150.00816.86
7.4.330.0030.00315.55
7.4.320.0030.00316.69
7.4.300.0030.00316.56
7.4.290.0000.00716.39
7.4.280.0040.00416.54
7.4.270.0070.00016.63
7.4.260.0030.00316.62
7.4.250.0020.00516.43
7.4.240.0000.00816.63
7.4.230.0000.00816.64
7.4.220.0070.01116.45
7.4.210.0100.00716.64
7.4.200.0000.00716.64
7.4.160.0080.01016.44
7.4.150.0070.01117.40
7.4.140.0120.00617.86
7.4.130.0160.00616.53
7.4.120.0100.01016.50
7.4.110.0150.00316.58
7.4.100.0070.01516.59
7.4.90.0150.00316.55
7.4.80.0140.00319.39
7.4.70.0120.00416.62
7.4.60.0130.00316.56
7.4.50.0070.01116.56
7.4.40.0000.01516.63
7.4.30.0100.01316.54
7.4.00.0000.01614.75
7.3.330.0060.00013.39
7.3.320.0050.00013.24
7.3.310.0070.00016.51
7.3.300.0030.00316.42
7.3.290.0050.01216.43
7.3.280.0100.00816.39
7.3.270.0040.01217.40
7.3.260.0080.01016.62
7.3.250.0130.00716.49
7.3.240.0120.00816.41
7.3.230.0060.01216.60
7.3.210.0110.00616.54
7.3.200.0060.00916.35
7.3.190.0070.01016.50
7.3.180.0090.00616.30
7.3.170.0070.01016.61
7.3.160.0120.00316.42
7.2.330.0030.01516.52
7.2.320.0090.01316.84
7.2.310.0030.02016.88
7.2.300.0090.00916.80
7.2.290.0130.00316.55
7.2.60.0070.00716.98
7.2.00.0040.01119.35
7.1.200.0040.01115.80
7.1.100.0060.00618.02
7.1.70.0040.01316.93
7.1.60.0180.01835.15
7.1.50.0150.01534.88
7.1.40.0200.01334.46
7.1.30.0190.01534.66
7.1.20.0200.01034.45
7.1.10.0160.00316.61
7.1.00.0060.00916.54
7.0.200.0060.01016.68
7.0.190.0080.00816.68
7.0.180.0090.01016.21
7.0.170.0030.01216.18
7.0.160.0090.00616.21
7.0.150.0130.00716.20
7.0.140.0040.01116.40
7.0.130.0090.00616.58
7.0.120.0000.01416.29
7.0.110.0060.00916.37
7.0.100.0030.01016.09
7.0.90.0060.01216.21
7.0.80.0050.01116.46
7.0.70.0060.00916.40
7.0.60.0030.01216.20
7.0.50.0080.00616.39
7.0.40.0060.00916.38
7.0.30.0080.00816.42
7.0.20.0090.00616.46
7.0.10.0030.01216.29
7.0.00.0000.01416.57

preferences:
41.28 ms | 401 KiB | 5 Q