3v4l.org

run code in 300+ PHP versions simultaneously
<?php //---------------------------------- // array_unique() semi-replacements //---------------------------------- // @link http://php.net/manual/en/function.array-unique.php#98453 function wp_array_unique1( $arr = array() ) { $tmp = array(); foreach( $arr as $key => $val ) { $tmp[$val] = true; } return array_keys( $tmp ); } // @link http://www.puremango.co.uk/2010/06/fast-php-array_unique-for-removing-duplicates/#comment-202704 function wp_array_unique2( $arr = array() ) { $tempArray = array(); foreach($arr as $key => $val ) { if( isset( $tempArray[$val] ) ) continue; $tempArray[$val] = $key; } return array_flip($tempArray); } // @link http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip function wp_array_unique3( $arr = array() ) { // Code documented at: http://www.puremango.co.uk/?p=1039 return array_flip(array_flip(array_reverse($arr,true))); } // @link http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip function wp_array_unique4( $arr = array() ) { return array_keys( array_flip( $arr ) ); } // @link http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip function wp_array_unique5( $arr = array() ) { return array_flip( array_flip( $arr ) ); } //---------- // Input //---------- $input = array( 0 => 1, 1 => 2, 2 => 2, 3 => 0, 4 => -1, 5 => '', 6 => null, 7 => 'Test', 8 => 0.1, 9 => 0.11, '1' => 1, 'a' => 'c', 'b' => 'a', 'c' => 'c' ); //------------------- // Test comparisions //------------------- echo 'Input:'; print_r( $input ); echo 'array_unique: '; print_r( array_unique( $input ) ); echo 'Replacement #1: '; print_r( wp_array_unique1( $input ) ); echo 'Replacement #2: '; print_r( wp_array_unique2( $input ) ); echo 'Replacement #3: '; print_r( wp_array_unique3( $input ) ); echo 'Replacement #4: '; print_r( wp_array_unique4( $input ) ); echo 'Replacement #5: '; print_r( wp_array_unique5( $input ) );

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.86
8.3.50.0100.01121.99
8.3.40.0120.00918.93
8.3.30.0040.01118.79
8.3.20.0080.00020.21
8.3.10.0030.00623.54
8.3.00.0080.00019.38
8.2.180.0090.00618.67
8.2.170.0110.00722.96
8.2.160.0070.00722.96
8.2.150.0030.00624.18
8.2.140.0000.00724.66
8.2.130.0050.00326.16
8.2.120.0000.00821.19
8.2.110.0000.01020.91
8.2.100.0060.00617.91
8.2.90.0060.00319.94
8.2.80.0000.00820.36
8.2.70.0030.00617.75
8.2.60.0050.00318.05
8.2.50.0060.00318.07
8.2.40.0040.00419.32
8.2.30.0040.00420.59
8.2.20.0080.00017.66
8.2.10.0040.00418.27
8.2.00.0060.00318.05
8.1.280.0040.01425.92
8.1.270.0060.00323.79
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0030.00722.42
8.1.230.0060.00622.73
8.1.220.0040.00417.77
8.1.210.0110.00019.00
8.1.200.0030.00617.35
8.1.190.0060.00317.23
8.1.180.0050.00318.10
8.1.170.0040.00420.43
8.1.160.0040.00422.07
8.1.150.0050.00318.89
8.1.140.0030.00519.59
8.1.130.0040.00417.62
8.1.120.0030.00317.49
8.1.110.0050.00217.42
8.1.100.0070.00017.50
8.1.90.0000.00717.52
8.1.80.0040.00417.37
8.1.70.0070.00017.46
8.1.60.0030.00617.64
8.1.50.0070.00317.46
8.1.40.0000.00717.56
8.1.30.0030.00517.68
8.1.20.0020.00517.66
8.1.10.0030.00617.57
8.1.00.0050.00317.40
8.0.300.0000.00720.14
8.0.290.0040.00416.63
8.0.280.0040.00418.46
8.0.270.0070.00017.29
8.0.260.0030.00317.26
8.0.250.0030.00517.02
8.0.240.0000.01017.04
8.0.230.0070.00016.92
8.0.220.0060.00316.95
8.0.210.0070.00016.94
8.0.200.0030.00316.99
8.0.190.0060.00317.12
8.0.180.0070.00016.96
8.0.170.0030.00516.86
8.0.160.0000.00716.96
8.0.150.0030.00316.99
8.0.140.0000.00816.95
8.0.130.0000.00713.43
8.0.120.0080.00016.94
8.0.110.0080.00017.01
8.0.100.0040.00416.75
8.0.90.0000.00816.79
8.0.80.0120.00417.00
8.0.70.0050.00216.90
8.0.60.0080.00016.77
8.0.50.0030.00517.03
8.0.30.0100.01017.21
8.0.20.0130.00717.40
8.0.10.0040.00417.05
8.0.00.0100.01216.88
7.4.330.0030.00315.08
7.4.320.0000.00816.60
7.4.300.0070.00016.52
7.4.290.0000.00716.55
7.4.280.0000.00716.40
7.4.270.0090.00016.57
7.4.260.0000.00716.43
7.4.250.0040.00416.53
7.4.240.0020.00516.45
7.4.230.0000.00716.41
7.4.220.0060.01216.55
7.4.210.0060.01016.64
7.4.200.0000.00716.68
7.4.160.0120.00316.53
7.4.150.0060.01317.40
7.4.140.0110.01117.86
7.4.130.0150.00216.54
7.4.120.0120.00616.56
7.4.110.0060.01616.69
7.4.100.0150.00616.59
7.4.90.0220.00316.63
7.4.80.0120.00719.39
7.4.70.0120.00416.50
7.4.60.0120.00416.75
7.4.50.0040.00016.34
7.4.40.0030.01416.43
7.4.30.0090.00916.52
7.4.00.0070.00614.91
7.3.330.0020.00213.31
7.3.320.0030.00313.31
7.3.310.0040.00416.43
7.3.300.0030.00316.45
7.3.290.0080.01016.40
7.3.280.0070.01116.47
7.3.270.0120.00617.40
7.3.260.0180.00416.49
7.3.250.0090.00916.46
7.3.240.0140.00716.47
7.3.230.0210.00316.59
7.3.210.0130.00416.42
7.3.200.0090.00616.67
7.3.190.0060.01416.65
7.3.180.0070.01016.54
7.3.170.0060.01216.52
7.3.160.0100.00716.68
7.2.330.0110.00716.62
7.2.320.0060.01616.40
7.2.310.0100.00716.64
7.2.300.0110.00516.41
7.2.290.0130.00716.78
7.2.60.0040.00816.99
7.2.50.0070.00716.64
7.2.00.0100.00319.14
7.1.200.0100.00315.68
7.1.100.0030.00718.15
7.1.70.0000.00817.25
7.1.60.0130.01019.43
7.1.50.0090.01217.00
7.1.00.0070.07322.43
7.0.200.0280.00714.90
7.0.60.0070.08319.91
7.0.50.0030.08317.95
7.0.40.0000.05720.13
7.0.30.0300.07020.22
7.0.20.0330.04320.26
7.0.10.0100.05720.34
7.0.00.0070.06320.20
5.6.280.0130.06320.91
5.6.210.0030.04020.70
5.6.200.0030.04018.18
5.6.190.0030.06720.55
5.6.180.0200.08020.61
5.6.170.0300.07720.71
5.6.160.0070.09020.57
5.6.150.0100.04318.25
5.6.140.0200.07318.24
5.6.130.0130.07718.18
5.6.120.0100.07021.06
5.6.110.0030.09720.98
5.6.100.0030.04321.01
5.6.90.0030.05720.99
5.6.80.0130.08020.54
5.5.350.0430.07020.41
5.5.340.0000.04018.04
5.5.330.0030.09020.13
5.5.320.0230.03720.52
5.5.310.0230.04020.39
5.5.300.0100.04017.98
5.5.290.0000.07317.94
5.5.280.0030.04020.69
5.5.270.0170.05020.77
5.5.260.0030.09020.64
5.5.250.0130.05320.47
5.5.240.0100.07320.17
5.4.450.0470.06019.31
5.4.440.0600.05319.30
5.4.430.0600.05019.47
5.4.420.0600.05319.60
5.4.410.0570.06319.34
5.4.400.0730.04319.22
5.4.390.0500.06019.25
5.4.380.0470.06019.30
5.4.370.0430.06319.34
5.4.360.0600.04719.16
5.4.350.0670.04319.30
5.4.340.0600.05019.37
5.4.320.0570.06018.84
5.4.310.0670.03718.98
5.4.300.0600.06019.21
5.4.290.0700.05319.24
5.4.280.0570.06719.16
5.4.270.0670.05018.86
5.4.260.0570.04719.23
5.4.250.0530.05319.14
5.4.240.0630.04319.13
5.4.230.0700.07019.11
5.4.220.0600.06019.21
5.4.210.0600.04719.25
5.4.200.0570.05019.35
5.4.190.0670.04019.34
5.4.180.0730.04319.34
5.4.170.0570.05719.27
5.4.160.0730.04318.99
5.4.150.0570.05319.34
5.4.140.0630.04016.46
5.4.130.0470.05316.43
5.4.120.0570.04716.57
5.4.110.0570.05016.67
5.4.100.0470.05716.66
5.4.90.0630.05716.58
5.4.80.0530.06316.66
5.4.70.0530.05016.62
5.4.60.0600.04316.26
5.4.50.0570.04716.59
5.4.40.0530.04716.49
5.4.30.0500.06016.58
5.4.20.0570.04316.55
5.4.10.0470.06016.59
5.4.00.0570.05015.79

preferences:
57.3 ms | 401 KiB | 5 Q