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 &$array, $sortKey = null, $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( ( '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', '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.70.0120.00318.68
8.3.60.0100.01616.75
8.3.50.0050.01116.61
8.3.40.0150.00018.84
8.3.30.0190.00318.80
8.3.20.0030.00520.16
8.3.10.0030.00623.65
8.3.00.0040.01121.89
8.2.190.0140.00417.00
8.2.180.0070.01016.75
8.2.170.0150.00022.96
8.2.160.0030.01719.16
8.2.150.0030.00524.18
8.2.140.0140.00424.66
8.2.130.0080.00021.13
8.2.120.0080.00826.35
8.2.110.0070.00421.02
8.2.100.0110.00017.84
8.2.90.0080.00019.40
8.2.80.0040.00418.03
8.2.70.0000.01017.75
8.2.60.0000.00818.05
8.2.50.0030.00618.10
8.2.40.0080.00020.37
8.2.30.0040.00419.21
8.2.20.0030.00818.15
8.2.10.0040.00418.16
8.2.00.0040.00418.14
8.1.280.0090.00925.92
8.1.270.0110.00422.20
8.1.260.0070.00726.35
8.1.250.0050.00328.09
8.1.240.0000.00922.68
8.1.230.0070.00319.10
8.1.220.0040.00417.79
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0040.00417.35
8.1.180.0030.00618.10
8.1.170.0100.00018.50
8.1.160.0040.00419.08
8.1.150.0020.00520.76
8.1.140.0050.00219.64
8.1.130.0000.00718.90
8.1.120.0040.00417.48
8.1.110.0000.00817.43
8.1.100.0050.00217.45
8.1.90.0070.00017.46
8.1.80.0050.00317.45
8.1.70.0050.00317.48
8.1.60.0030.00617.53
8.1.50.0000.00817.57
8.1.40.0040.00417.51
8.1.30.0000.00817.56
8.1.20.0060.00317.63
8.1.10.0090.00017.51
8.1.00.0080.00017.50
8.0.300.0070.00019.99
8.0.290.0070.00016.88
8.0.280.0040.00418.39
8.0.270.0050.00317.28
8.0.260.0030.00316.78
8.0.250.0030.00316.98
8.0.240.0090.00016.91
8.0.230.0070.00016.97
8.0.220.0030.00316.89
8.0.210.0040.00416.88
8.0.200.0030.00316.93
8.0.190.0030.00617.07
8.0.180.0070.00017.02
8.0.170.0040.00417.01
8.0.160.0040.00416.97
8.0.150.0000.00716.96
8.0.140.0050.00217.00
8.0.130.0000.00613.36
8.0.120.0000.00816.96
8.0.110.0040.00416.93
8.0.100.0000.00716.88
8.0.90.0000.00716.97
8.0.80.0030.01316.99
8.0.70.0040.00416.95
8.0.60.0080.00016.88
8.0.50.0000.00716.77
8.0.30.0110.00517.30
8.0.20.0070.01117.40
8.0.10.0040.00416.98
8.0.00.0070.01017.00
7.4.330.0030.00315.55
7.4.320.0000.00616.54
7.4.300.0060.00016.47
7.4.290.0030.00316.46
7.4.280.0030.00316.54
7.4.270.0030.00316.44
7.4.260.0070.00016.56
7.4.250.0030.00316.50
7.4.240.0000.00816.55
7.4.230.0040.00416.65
7.4.220.0110.00716.63
7.4.210.0030.01316.48
7.4.200.0030.00316.42
7.4.160.0090.00616.60
7.4.150.0070.01017.40
7.4.140.0050.01317.86
7.4.130.0110.00716.37
7.4.120.0110.01116.52
7.4.110.0140.01116.65
7.4.100.0100.01016.48
7.4.90.0090.00616.41
7.4.80.0030.01419.39
7.4.70.0060.01116.72
7.4.60.0060.01016.55
7.4.50.0040.01116.62
7.4.40.0110.00516.44
7.4.30.0080.00816.47
7.4.10.0060.01416.52
7.4.00.0070.00915.75
7.3.330.0000.00613.23
7.3.320.0030.00313.18
7.3.310.0000.00716.39
7.3.300.0000.00716.41
7.3.290.0080.00816.40
7.3.280.0060.01016.38
7.3.270.0130.00617.40
7.3.260.0060.01216.55
7.3.250.0110.00716.40
7.3.240.0140.00716.58
7.3.230.0100.00716.60
7.3.210.0170.00016.50
7.3.200.0120.00916.59
7.3.190.0110.00716.33
7.3.180.0150.00616.65
7.3.170.0130.00316.56
7.3.160.0030.01316.36
7.3.130.0060.01316.34
7.3.120.0100.00716.52
7.3.110.0100.00316.54
7.3.100.0110.00416.47
7.3.90.0060.00916.27
7.3.80.0100.01016.34
7.3.70.0040.01116.23
7.3.60.0030.00716.38
7.3.50.0110.00716.39
7.3.40.0070.00716.24
7.3.30.0030.01216.53
7.3.20.0060.00818.11
7.3.10.0030.01318.14
7.3.00.0060.00618.08
7.2.330.0100.00716.75
7.2.320.0030.01616.59
7.2.310.0100.00916.65
7.2.300.0120.00616.63
7.2.290.0090.00816.69
7.2.260.0060.00916.88
7.2.250.0070.01316.68
7.2.240.0140.00416.68
7.2.230.0070.01116.70
7.2.220.0090.00616.49
7.2.210.0100.00716.58
7.2.200.0060.00616.46
7.2.190.0070.00716.64
7.2.180.0100.00716.73
7.2.170.0040.00816.47
7.2.160.0070.00716.65
7.2.150.0100.00318.36
7.2.140.0120.00418.36
7.2.130.0040.01118.40
7.2.120.0090.00918.45
7.2.110.0060.01018.45
7.2.100.0050.00818.44
7.2.90.0120.00018.59
7.2.80.0030.01318.44
7.2.70.0040.01418.36
7.2.60.0050.01117.61
7.2.50.0100.00718.37
7.2.40.0060.01218.29
7.2.30.0100.00718.55
7.2.20.0090.00318.54
7.2.10.0060.01018.43
7.2.00.0040.00919.02
7.1.330.0060.00917.55
7.1.320.0000.01117.54
7.1.310.0070.00717.48
7.1.300.0090.00617.45
7.1.290.0050.00517.52
7.1.280.0060.00317.46
7.1.270.0110.00317.34
7.1.260.0030.00917.37
7.1.250.0110.00717.28
7.1.240.0120.00317.19
7.1.230.0040.01117.22
7.1.220.0090.00917.50
7.1.210.0040.01117.30
7.1.200.0040.00816.49
7.1.190.0030.00617.44
7.1.180.0110.00417.27
7.1.170.0130.00317.48
7.1.160.0100.00017.50
7.1.150.0090.00617.29
7.1.140.0090.00617.37
7.1.130.0040.01117.44
7.1.120.0070.00717.34
7.1.110.0110.00317.29
7.1.100.0020.00817.79
7.1.90.0040.00817.32
7.1.80.0000.01517.36
7.1.70.0070.01017.41
7.1.60.0130.01126.27
7.1.50.0160.01126.12
7.1.40.0140.00925.94
7.1.30.0170.01125.96
7.1.20.0090.01625.90
7.1.10.0040.01316.97
7.1.00.0080.01017.00
7.0.330.0070.01017.02
7.0.320.0000.01017.09
7.0.310.0000.01117.00
7.0.300.0100.00317.15
7.0.290.0040.01116.96
7.0.280.0070.00716.91
7.0.270.0060.00917.03
7.0.260.0060.00617.18
7.0.250.0060.00917.00
7.0.240.0070.00716.91
7.0.230.0070.00716.89
7.0.220.0070.01117.13
7.0.210.0030.01016.99
7.0.200.0060.01216.87
7.0.190.0060.00916.67
7.0.180.0080.01016.74
7.0.170.0110.00616.64
7.0.160.0030.01116.74
7.0.150.0070.01116.71
7.0.140.0080.01116.60
7.0.130.0100.01016.69
7.0.120.0090.01116.77
7.0.110.0110.00716.74
7.0.100.0050.01316.74
7.0.90.0070.01016.64
7.0.80.0050.01516.66
7.0.70.0080.01216.64
7.0.60.0070.00816.55
7.0.50.0050.01116.62
7.0.40.0100.00815.69
7.0.30.0090.00915.64
7.0.20.0100.00715.67
7.0.10.0100.00715.67
7.0.00.0090.00915.71
5.6.400.0040.00815.35
5.6.390.0040.00715.70
5.6.380.0040.01115.47
5.6.370.0060.00615.69
5.6.360.0030.01215.74
5.6.350.0030.01015.57
5.6.340.0040.01115.78
5.6.330.0090.00615.68
5.6.320.0070.00715.39
5.6.310.0070.00715.69
5.6.300.0100.03418.36
5.6.290.0060.04818.12
5.6.280.0060.04218.17
5.6.270.0130.03818.23
5.6.260.0040.04118.15
5.6.250.0100.04118.39
5.6.240.0090.04618.24
5.6.230.0030.04418.23
5.6.220.0100.03918.24
5.6.210.0050.04418.19
5.6.200.0110.04018.23
5.6.190.0090.03818.34
5.6.180.0080.03918.12
5.6.170.0090.04418.28
5.6.160.0080.03818.15
5.6.150.0040.05118.30
5.6.140.0080.03918.28
5.6.130.0080.04018.18
5.6.120.0080.04818.14
5.6.110.0090.04718.19
5.6.100.0080.04618.05
5.6.90.0120.04018.15
5.6.80.0060.04717.82
5.6.70.0080.03917.82
5.6.60.0080.04617.84
5.6.50.0030.04517.81
5.6.40.0080.04317.93
5.6.30.0110.02917.91
5.6.20.0080.04617.79
5.6.10.0080.04017.78
5.6.00.0100.03517.91
5.5.380.0130.07417.41
5.5.370.0170.05117.48
5.5.360.0160.06917.52
5.5.350.0030.07317.47
5.5.340.0100.06918.04
5.5.330.0140.06118.04
5.5.320.0090.06517.96
5.5.310.0120.08017.80
5.5.300.0070.05918.04
5.5.290.0060.08118.12
5.5.280.0030.09018.04
5.5.270.0230.06918.02
5.5.260.0100.06517.94
5.5.250.0100.08417.56
5.5.240.0070.07517.13
5.5.230.0060.08017.34
5.5.220.0170.07517.40
5.5.210.0060.07917.41
5.5.200.0130.06917.41
5.5.190.0140.07017.37
5.5.180.0190.06317.13
5.5.160.0120.06917.40
5.5.150.0120.05317.07
5.5.140.0100.07117.31
5.5.130.0030.05917.43
5.5.120.0120.07117.05
5.5.110.0070.05517.05
5.5.100.0030.06017.38
5.5.90.0070.05417.21
5.5.80.0000.06217.21
5.5.70.0070.05717.26
5.5.60.0030.05817.19
5.5.50.0100.06517.04
5.5.40.0060.07717.27
5.5.30.0090.07017.27
5.5.20.0100.07617.36
5.5.10.0070.07916.96
5.5.00.0030.06417.25
5.4.450.0180.07419.19
5.4.440.0210.07619.38
5.4.430.0130.07619.38
5.4.420.0180.06819.47
5.4.410.0120.08619.23
5.4.400.0060.07518.96
5.4.390.0090.07918.92
5.4.380.0030.08319.02
5.4.370.0100.05518.88
5.4.360.0130.06519.15
5.4.350.0130.07319.24
5.4.340.0130.07018.99
5.4.320.0100.07719.03
5.4.310.0070.07718.93
5.4.300.0210.05819.05
5.4.290.0090.05819.01
5.4.280.0130.05219.23
5.4.270.0100.06518.92
5.4.260.0150.06318.86
5.4.250.0160.05819.14
5.4.240.0060.05718.83
5.4.230.0060.06119.10
5.4.220.0060.06119.01
5.4.210.0130.06019.07
5.4.200.0160.06818.86
5.4.190.0090.07618.97
5.4.180.0150.06918.86
5.4.170.0000.06719.07
5.4.160.0180.04818.96
5.4.150.0100.05818.93
5.4.140.0170.04316.71
5.4.130.0150.05016.71
5.4.120.0090.05416.48
5.4.110.0070.07816.61
5.4.100.0080.04816.77
5.4.90.0060.05216.70
5.4.80.0100.05716.71
5.4.70.0040.07416.68
5.4.60.0060.06216.57
5.4.50.0180.05116.41
5.4.40.0100.05116.66
5.4.30.0040.06016.39
5.4.20.0090.05116.66
5.4.10.0100.05716.39
5.4.00.0130.06016.12
5.3.290.0180.06314.96
5.3.280.0070.07014.73
5.3.270.0100.07314.89
5.3.260.0090.06714.50
5.3.250.0150.04614.68
5.3.240.0200.04414.67
5.3.230.0160.05414.48
5.3.220.0100.06014.66
5.3.210.0100.05314.89
5.3.200.0090.05314.46
5.3.190.0220.04714.63
5.3.180.0130.06114.76
5.3.170.0030.07614.86
5.3.160.0060.07414.77
5.3.150.0090.06514.86
5.3.140.0100.05214.84
5.3.130.0120.05514.84
5.3.120.0060.06714.84
5.3.110.0060.07014.83
5.3.100.0140.05414.05
5.3.90.0090.06814.09
5.3.80.0120.06214.31
5.3.70.0170.05714.21
5.3.60.0030.06614.02
5.3.50.0100.06214.27
5.3.40.0160.06014.25
5.3.30.0070.07013.79
5.3.20.0140.05813.59
5.3.10.0030.07213.88
5.3.00.0000.07813.94
5.2.170.0070.04111.13
5.2.160.0120.04711.29
5.2.150.0070.05811.07
5.2.140.0120.05411.37
5.2.130.0130.04611.07
5.2.120.0070.05611.34
5.2.110.0060.05311.09
5.2.100.0030.04210.91
5.2.90.0060.04211.21
5.2.80.0100.05611.07
5.2.70.0070.05911.14
5.2.60.0090.04211.18
5.2.50.0160.04311.23
5.2.40.0090.04711.13
5.2.30.0100.04611.11
5.2.20.0110.05211.18
5.2.10.0060.04410.86
5.2.00.0000.05410.92
5.1.60.0070.04510.23
5.1.50.0000.04210.03
5.1.40.0090.03210.14
5.1.30.0090.04210.59
5.1.20.0090.04610.52
5.1.10.0070.0349.96
5.1.00.0000.05310.23
5.0.50.0040.0418.42
5.0.40.0060.0368.63
5.0.30.0070.0588.54
5.0.20.0090.0358.41
5.0.10.0070.0338.21
5.0.00.0100.0568.11
4.4.90.0090.0236.63
4.4.80.0030.0226.63
4.4.70.0050.0256.63
4.4.60.0060.0196.63
4.4.50.0030.0236.63
4.4.40.0060.0326.63
4.4.30.0060.0226.63
4.4.20.0130.0196.63
4.4.10.0030.0306.63
4.4.00.0050.0426.63
4.3.110.0040.0326.63
4.3.100.0070.0276.63
4.3.90.0060.0236.63
4.3.80.0030.0446.63
4.3.70.0090.0256.63
4.3.60.0050.0266.63
4.3.50.0060.0286.63
4.3.40.0030.0456.63
4.3.30.0100.0266.63
4.3.20.0060.0266.63
4.3.10.0120.0246.63
4.3.00.0000.0316.63

preferences:
49.51 ms | 401 KiB | 5 Q