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 array sorted by sortBy(). */ public static function sortBy( &$array, $sortKey, $dir = 'ASC', $nat = false ) { if ( null === static::$instance ) { static::$instance = new static(); }; function sortLogic( $key, $dir, bool $nat ) { return function( $a, $b ) use ( $key, $dir, $nat ) { if ( true === $nat ){ return strnatcmp( $a[$key], $b[$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', 'ASC', 'cat' ); 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.0040.01116.75
8.3.50.0120.00316.38
8.3.40.0090.00618.67
8.3.30.0040.01118.76
8.3.20.0080.00020.10
8.3.10.0000.01023.53
8.3.00.0050.00322.07
8.2.180.0070.01118.26
8.2.170.0090.00622.96
8.2.160.0100.00718.91
8.2.150.0040.00424.18
8.2.140.0070.01124.66
8.2.130.0080.00021.03
8.2.120.0040.01126.35
8.2.110.0070.00319.04
8.2.100.0090.00317.98
8.2.90.0000.00819.20
8.2.80.0000.00817.97
8.2.70.0090.00017.63
8.2.60.0000.00818.16
8.2.50.0030.00618.10
8.2.40.0060.00320.65
8.2.30.0000.00819.20
8.2.20.0000.01018.18
8.2.10.0000.00718.14
8.2.00.0000.00818.12
8.1.280.0100.00725.92
8.1.270.0070.00722.10
8.1.260.0070.00726.35
8.1.250.0040.00428.09
8.1.240.0090.00022.71
8.1.230.0060.00619.11
8.1.220.0040.00417.74
8.1.210.0060.00318.77
8.1.200.0090.00017.22
8.1.190.0040.00417.23
8.1.180.0040.00418.10
8.1.170.0080.00318.53
8.1.160.0040.00418.94
8.1.150.0040.00420.59
8.1.140.0040.00419.70
8.1.130.0030.00617.34
8.1.120.0040.00417.47
8.1.110.0000.00817.46
8.1.100.0000.00717.52
8.1.90.0080.00017.43
8.1.80.0040.00417.46
8.1.70.0000.00717.37
8.1.60.0040.00417.59
8.1.50.0040.00417.49
8.1.40.0030.00517.34
8.1.30.0060.00317.57
8.1.20.0000.00817.62
8.1.10.0080.00017.62
8.1.00.0080.00017.53
8.0.300.0040.00420.06
8.0.290.0060.00316.75
8.0.280.0040.00418.50
8.0.270.0000.00717.26
8.0.260.0000.00716.94
8.0.250.0000.00716.96
8.0.240.0060.00316.99
8.0.230.0070.00017.04
8.0.220.0000.00816.99
8.0.210.0070.00017.02
8.0.200.0030.00316.98
8.0.190.0060.00317.02
8.0.180.0030.00516.96
8.0.170.0040.00416.88
8.0.160.0040.00417.02
8.0.150.0000.00716.97
8.0.140.0040.00416.95
8.0.130.0000.00613.35
8.0.120.0080.00016.94
8.0.110.0040.00416.84
8.0.100.0070.00016.93
8.0.90.0000.00717.07
8.0.80.0000.02316.92
8.0.70.0040.00416.93
8.0.60.0000.00816.96
8.0.50.0040.00416.93
8.0.30.0100.00917.07
8.0.20.0120.01017.41
8.0.10.0020.00517.00
8.0.00.0120.00616.84
7.4.330.0000.00615.55
7.4.320.0030.00316.51
7.4.300.0000.00616.52
7.4.290.0000.00716.50
7.4.280.0030.00516.54
7.4.270.0000.00716.45
7.4.260.0070.00016.64
7.4.250.0000.00816.39
7.4.240.0030.00316.60
7.4.230.0000.00716.63
7.4.220.0150.01116.44
7.4.210.0070.00716.64
7.4.200.0030.00516.64
7.4.160.0070.00816.64
7.4.150.0060.01117.40
7.4.140.0130.00617.86
7.4.130.0170.00716.64
7.4.120.0130.01016.44
7.4.110.0120.00616.48
7.4.100.0030.01716.35
7.4.90.0070.01016.51
7.4.80.0000.02219.39
7.4.70.0060.00916.38
7.4.60.0100.00716.46
7.4.50.0110.00316.66
7.4.40.0060.01016.58
7.4.30.0080.00816.61
7.4.10.0030.01416.48
7.4.00.0080.00515.62
7.3.330.0030.00313.34
7.3.320.0020.00313.31
7.3.310.0030.00316.34
7.3.300.0040.00416.34
7.3.290.0040.01316.41
7.3.280.0080.00916.34
7.3.270.0090.00917.40
7.3.260.0130.00516.68
7.3.250.0100.00816.45
7.3.240.0050.01316.53
7.3.230.0120.00616.46
7.3.210.0130.00316.26
7.3.200.0060.01216.67
7.3.190.0040.01516.57
7.3.180.0090.00616.57
7.3.170.0140.00316.61
7.3.160.0120.00616.55
7.3.130.0060.01316.34
7.3.120.0070.01016.30
7.3.110.0070.00716.46
7.3.100.0060.00916.24
7.3.90.0090.00616.34
7.3.80.0070.00716.26
7.3.70.0060.00916.29
7.3.60.0130.00316.34
7.3.50.0030.00816.54
7.3.40.0040.00416.38
7.3.30.0100.00716.26
7.3.20.0110.00718.13
7.3.10.0130.00618.12
7.3.00.0070.00718.21
7.2.330.0120.00616.61
7.2.320.0090.01016.59
7.2.310.0140.00716.80
7.2.300.0060.01616.52
7.2.290.0090.00616.94
7.2.260.0070.01116.49
7.2.250.0070.01416.80
7.2.240.0000.01016.76
7.2.230.0100.00316.73
7.2.220.0090.00316.47
7.2.210.0030.01016.68
7.2.200.0030.01316.58
7.2.190.0030.01216.68
7.2.180.0040.00816.59
7.2.170.0070.00716.52
7.2.160.0000.01616.58
7.2.150.0170.00018.43
7.2.140.0070.01018.52
7.2.130.0070.00718.52
7.2.120.0070.00418.54
7.2.110.0060.00918.48
7.2.100.0040.01118.48
7.2.90.0030.01218.48
7.2.80.0130.00018.36
7.2.70.0100.00718.34
7.2.60.0060.00917.50
7.2.50.0040.01218.44
7.2.40.0110.00418.50
7.2.30.0060.00618.50
7.2.20.0040.01118.49
7.2.10.0030.01318.39
7.2.00.0050.00918.82
7.1.330.0110.00417.39
7.1.320.0070.00717.43
7.1.310.0040.01417.58
7.1.300.0060.00617.32
7.1.290.0060.00317.31
7.1.280.0130.00617.24
7.1.270.0040.01517.40
7.1.260.0070.00717.45
7.1.250.0070.00717.16
7.1.240.0070.00717.27
7.1.230.0140.00017.48
7.1.220.0090.00617.33
7.1.210.0040.01117.43
7.1.200.0070.00716.47
7.1.190.0040.01417.26
7.1.180.0070.01017.23
7.1.170.0040.00717.34
7.1.160.0070.00717.29
7.1.150.0050.00617.24
7.1.140.0150.00417.27
7.1.130.0030.01017.43
7.1.120.0070.00717.25
7.1.110.0000.01417.50
7.1.100.0000.01017.53
7.1.90.0090.00617.32
7.1.80.0060.00617.20
7.1.70.0050.01117.27
7.1.60.0130.01426.26
7.1.50.0090.01326.04
7.1.40.0170.01125.79
7.1.30.0130.01326.11
7.1.20.0170.00925.99
7.1.10.0060.01216.91
7.1.00.0050.00917.01
7.0.330.0030.00917.04
7.0.320.0040.01117.07
7.0.310.0060.00917.11
7.0.300.0000.01617.16
7.0.290.0070.00717.08
7.0.280.0130.00317.10
7.0.270.0060.00916.96
7.0.260.0070.00717.05
7.0.250.0040.01117.18
7.0.240.0070.00717.11
7.0.230.0030.00717.18
7.0.220.0100.00617.15
7.0.210.0070.01317.21
7.0.200.0120.00316.95
7.0.190.0120.00516.91
7.0.180.0090.00816.68
7.0.170.0090.00716.68
7.0.160.0070.00916.69
7.0.150.0060.01116.79
7.0.140.0090.00516.75
7.0.130.0080.00716.78
7.0.120.0050.01316.83
7.0.110.0060.00816.63
7.0.100.0090.00316.74
7.0.90.0050.01116.61
7.0.80.0120.00616.59
7.0.70.0090.00916.66
7.0.60.0040.01016.65
7.0.50.0070.01516.71
7.0.40.0060.00915.62
7.0.30.0050.00815.84
7.0.20.0050.01115.72
7.0.10.0090.00515.60
7.0.00.0080.01015.60
5.6.400.0060.00316.24
5.6.390.0060.00616.26
5.6.380.0030.01015.87
5.6.370.0060.00916.21
5.6.360.0100.00615.79
5.6.350.0060.00915.91
5.6.340.0100.01016.09
5.6.330.0090.00016.14
5.6.320.0110.00416.20
5.6.310.0070.01316.31
5.6.300.0050.04618.69
5.6.290.0080.03318.21
5.6.280.0100.03018.29
5.6.270.0090.04018.39
5.6.260.0020.05018.56
5.6.250.0090.03118.31
5.6.240.0080.03518.54
5.6.230.0100.03118.34
5.6.220.0080.04118.36
5.6.210.0050.03718.35
5.6.200.0130.04218.45
5.6.190.0110.04218.26
5.6.180.0070.04718.38
5.6.170.0120.02718.36
5.6.160.0130.03718.34
5.6.150.0130.03818.55
5.6.140.0110.03618.35
5.6.130.0070.04818.28
5.6.120.0130.04618.48
5.6.110.0150.04018.28
5.6.100.0030.04118.31
5.6.90.0180.04118.42
5.6.80.0050.04718.08
5.6.70.0070.04918.04
5.6.60.0120.03818.28
5.6.50.0120.03818.20
5.6.40.0050.04217.99
5.6.30.0070.04618.17
5.6.20.0100.04018.01
5.6.10.0100.03118.02
5.6.00.0110.03717.94
5.5.380.0130.05317.61
5.5.370.0100.05717.56
5.5.360.0070.08017.55
5.5.350.0090.05917.52
5.5.340.0140.07418.03
5.5.330.0130.05118.07
5.5.320.0030.07017.75
5.5.310.0030.05818.02
5.5.300.0100.08017.96
5.5.290.0130.09218.03
5.5.280.0100.08518.13
5.5.270.0170.06317.77
5.5.260.0200.08418.01
5.5.250.0100.07717.95
5.5.240.0100.07617.19
5.5.230.0100.06417.51
5.5.220.0140.06817.31
5.5.210.0070.07217.40
5.5.200.0200.05417.36
5.5.190.0100.07717.04
5.5.180.0130.06117.10
5.5.160.0060.07517.15
5.5.150.0130.07117.09
5.5.140.0070.07117.48
5.5.130.0130.06817.20
5.5.120.0170.06717.35
5.5.110.0160.06517.47
5.5.100.0130.05217.06
5.5.90.0030.05717.31
5.5.80.0030.05417.27
5.5.70.0030.06017.27
5.5.60.0130.04617.28
5.5.50.0100.04817.21
5.5.40.0070.05117.29
5.5.30.0160.04417.27
5.5.20.0070.06017.18
5.5.10.0140.06817.30
5.5.00.0160.04617.26
5.4.450.0250.07519.32
5.4.440.0100.08619.47
5.4.430.0210.07119.18
5.4.420.0100.08819.56
5.4.410.0070.08119.06
5.4.400.0100.08219.02
5.4.390.0070.08018.95
5.4.380.0160.06418.92
5.4.370.0130.06218.84
5.4.360.0070.07419.05
5.4.350.0000.08419.08
5.4.340.0060.06519.00
5.4.320.0100.07618.83
5.4.310.0100.07219.02
5.4.300.0120.06918.84
5.4.290.0030.07518.86
5.4.280.0230.06018.98
5.4.270.0200.06718.92
5.4.260.0100.06218.95
5.4.250.0070.05618.92
5.4.240.0160.04818.92
5.4.230.0070.06319.01
5.4.220.0100.05119.14
5.4.210.0070.05319.14
5.4.200.0170.04319.05
5.4.190.0070.05318.91
5.4.180.0100.06919.25
5.4.170.0090.05418.99
5.4.160.0100.05019.13
5.4.150.0070.05619.08
5.4.140.0130.04316.80
5.4.130.0070.05716.69
5.4.120.0140.05516.69
5.4.110.0130.04816.48
5.4.100.0070.04916.70
5.4.90.0160.06816.72
5.4.80.0100.06816.75
5.4.70.0000.07016.71
5.4.60.0070.06816.64
5.4.50.0070.06916.61
5.4.40.0130.06616.60
5.4.30.0010.05716.65
5.4.20.0090.07816.66
5.4.10.0030.05516.60
5.4.00.0070.04915.98
5.3.290.0030.08014.98
5.3.280.0070.05314.74
5.3.270.0100.05514.75
5.3.260.0070.05614.81
5.3.250.0070.04914.93
5.3.240.0000.05614.82
5.3.230.0100.04814.90
5.3.220.0130.04514.73
5.3.210.0070.06214.45
5.3.200.0160.05914.59
5.3.190.0070.08114.65
5.3.180.0070.05014.88
5.3.170.0030.06114.80
5.3.160.0100.06614.86
5.3.150.0060.05214.79
5.3.140.0070.08314.84
5.3.130.0100.08314.85
5.3.120.0040.05814.79
5.3.110.0030.07514.85
5.3.100.0030.05814.34
5.3.90.0100.06514.22
5.3.80.0100.05014.13
5.3.70.0130.04314.04
5.3.60.0070.04714.20
5.3.50.0140.04114.28
5.3.40.0100.04614.15
5.3.30.0160.06914.14
5.3.20.0070.07113.78
5.3.10.0010.06313.85
5.3.00.0100.04813.95
5.2.170.0070.04311.19
5.2.160.0100.03711.07
5.2.150.0060.06911.09
5.2.140.0090.05811.07
5.2.130.0070.06111.09
5.2.120.0100.05511.32
5.2.110.0070.03711.32
5.2.100.0070.03711.30
5.2.90.0000.04311.30
5.2.80.0060.03911.02
5.2.70.0030.04511.33
5.2.60.0040.04211.16
5.2.50.0030.04211.25
5.2.40.0030.04311.21
5.2.30.0100.03910.98
5.2.20.0060.05810.96
5.2.10.0000.04710.91
5.2.00.0130.05410.88
5.1.60.0030.05110.15
5.1.50.0030.0509.97
5.1.40.0150.0289.85
5.1.30.0100.03510.63
5.1.20.0100.03110.40
5.1.10.0070.03310.37
5.1.00.0100.03610.22
5.0.50.0160.0258.63
5.0.40.0160.0198.55
5.0.30.0030.0438.24
5.0.20.0040.0308.39
5.0.10.0100.0248.25
5.0.00.0020.0448.47
4.4.90.0030.0226.63
4.4.80.0000.0246.63
4.4.70.0060.0296.63
4.4.60.0000.0326.63
4.4.50.0090.0186.63
4.4.40.0060.0316.63
4.4.30.0030.0226.63
4.4.20.0090.0166.63
4.4.10.0060.0226.63
4.4.00.0060.0316.63
4.3.110.0040.0216.63
4.3.100.0030.0226.63
4.3.90.0060.0186.63
4.3.80.0070.0306.63
4.3.70.0030.0396.63
4.3.60.0030.0216.63
4.3.50.0060.0186.63
4.3.40.0070.0306.63
4.3.30.0030.0236.63
4.3.20.0060.0216.63
4.3.10.0070.0196.63
4.3.00.0030.0226.63

preferences:
48.49 ms | 401 KiB | 5 Q