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 => '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.4.20.0080.00017.83
8.4.10.0100.01017.90
8.3.150.0120.00917.28
8.3.140.0040.00417.20
8.3.130.0070.00316.84
8.3.120.0130.00718.98
8.3.110.0060.00920.94
8.3.100.0080.01224.06
8.3.90.0080.00026.77
8.3.80.0050.00516.63
8.3.70.0150.00016.63
8.3.60.0120.00616.86
8.3.50.0170.00522.11
8.3.40.0060.01018.97
8.3.30.0140.00018.67
8.3.20.0040.00420.25
8.3.10.0050.00523.61
8.3.00.0040.00419.39
8.2.260.0160.00318.94
8.2.250.0040.00416.56
8.2.240.0120.00318.91
8.2.230.0060.00322.58
8.2.220.0000.00937.54
8.2.210.0070.01126.77
8.2.200.0040.00417.00
8.2.190.0070.01416.63
8.2.180.0120.00325.92
8.2.170.0160.00619.21
8.2.160.0100.00320.39
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0060.00326.16
8.2.120.0080.00019.91
8.2.110.0060.00319.27
8.2.100.0090.00317.84
8.2.90.0050.00319.25
8.2.80.0030.00617.97
8.2.70.0000.00817.63
8.2.60.0040.00417.75
8.2.50.0030.00517.63
8.2.40.0000.00719.46
8.2.30.0040.00420.70
8.2.20.0030.00517.70
8.2.10.0080.00018.04
8.2.00.0060.00318.01
8.1.310.0080.00016.61
8.1.300.0000.00820.08
8.1.290.0030.00718.88
8.1.280.0090.00625.92
8.1.270.0060.00323.86
8.1.260.0040.01228.09
8.1.250.0080.00028.09
8.1.240.0060.00322.05
8.1.230.0030.01017.70
8.1.220.0060.00317.76
8.1.210.0080.00018.77
8.1.200.0030.00617.35
8.1.190.0000.00817.35
8.1.180.0060.00318.10
8.1.170.0080.00018.64
8.1.160.0080.00022.01
8.1.150.0050.00218.90
8.1.140.0000.00819.52
8.1.130.0030.00517.50
8.1.120.0030.00317.49
8.1.110.0000.00717.46
8.1.100.0040.00417.52
8.1.90.0040.00417.43
8.1.80.0080.00017.41
8.1.70.0050.00217.45
8.1.60.0030.00617.59
8.1.50.0030.00617.58
8.1.40.0030.00517.53
8.1.30.0000.00817.55
8.1.20.0030.00617.71
8.1.10.0040.00417.57
8.1.00.0080.00017.46
8.0.300.0040.00419.60
8.0.290.0040.00416.75
8.0.280.0000.00718.33
8.0.270.0000.00716.89
8.0.260.0030.00516.84
8.0.250.0000.00716.93
8.0.240.0060.00316.92
8.0.230.0030.00317.04
8.0.220.0000.00816.87
8.0.210.0070.00016.94
8.0.200.0000.00717.08
8.0.190.0070.00017.06
8.0.180.0040.00416.88
8.0.170.0000.00816.98
8.0.160.0000.00716.83
8.0.150.0000.00716.84
8.0.140.0050.00216.96
8.0.130.0040.00413.41
8.0.120.0000.00816.99
8.0.110.0040.00416.93
8.0.100.0040.00416.99
8.0.90.0050.00316.87
8.0.80.0130.00317.02
8.0.70.0000.00716.96
8.0.60.0040.00416.82
8.0.50.0020.00517.01
8.0.30.0090.00817.03
8.0.20.0080.01017.40
8.0.10.0000.00817.13
8.0.00.0090.01217.00
7.4.330.0030.00315.13
7.4.320.0030.00516.50
7.4.300.0040.00416.60
7.4.290.0000.00716.41
7.4.280.0040.00416.50
7.4.270.0000.00816.62
7.4.260.0050.00316.54
7.4.250.0040.00416.52
7.4.240.0000.00816.62
7.4.230.0030.00316.41
7.4.220.0180.00016.70
7.4.210.0150.00016.63
7.4.200.0070.00016.54
7.4.160.0070.01016.72
7.4.150.0110.00817.40
7.4.140.0150.00517.86
7.4.130.0140.00716.57
7.4.120.0110.00716.55
7.4.110.0160.01016.50
7.4.100.0100.01016.52
7.4.90.0180.00016.72
7.4.80.0080.01419.39
7.4.70.0070.01416.46
7.4.60.0170.00416.56
7.4.50.0000.00916.66
7.4.40.0190.00016.35
7.4.30.0090.00916.66
7.4.10.0070.01215.04
7.4.00.0050.01115.00
7.3.330.0000.00613.46
7.3.320.0030.00313.43
7.3.310.0040.00416.50
7.3.300.0030.00316.41
7.3.290.0060.00716.43
7.3.280.0100.00816.46
7.3.270.0060.01217.40
7.3.260.0130.00316.50
7.3.250.0070.00916.47
7.3.240.0140.00416.59
7.3.230.0100.01016.62
7.3.210.0030.01316.45
7.3.200.0030.01316.44
7.3.190.0110.01116.40
7.3.180.0100.00716.50
7.3.170.0060.01616.49
7.3.160.0030.01416.57
7.3.130.0080.01114.78
7.3.120.0100.00814.68
7.3.110.0100.00814.53
7.3.100.0070.01014.93
7.3.90.0050.01115.01
7.3.80.0040.01215.07
7.3.70.0020.01114.74
7.3.60.0070.00914.95
7.3.50.0120.00514.83
7.3.40.0020.00914.86
7.3.30.0090.00614.72
7.3.20.0050.00816.49
7.3.10.0040.01016.74
7.3.00.0090.00416.61
7.2.330.0110.00816.71
7.2.320.0070.01716.70
7.2.310.0030.01316.53
7.2.300.0130.00716.73
7.2.290.0040.01516.57
7.2.260.0060.00814.93
7.2.250.0070.01215.05
7.2.240.0050.00914.91
7.2.230.0100.00315.14
7.2.220.0040.01314.98
7.2.210.0060.00714.87
7.2.200.0080.00615.12
7.2.190.0080.01115.04
7.2.180.0030.01115.02
7.2.170.0090.00614.98
7.2.160.0060.00815.07
7.2.150.0100.00816.86
7.2.140.0090.00716.85
7.2.130.0070.01116.88
7.2.120.0060.00916.93
7.2.110.0090.00416.84
7.2.100.0100.00616.76
7.2.90.0030.01116.84
7.2.80.0030.00716.90
7.2.70.0050.00917.02
7.2.60.0020.01216.76
7.2.50.0060.00616.68
7.2.40.0070.00516.80
7.2.30.0070.01016.84
7.2.20.0050.01016.74
7.2.10.0070.00716.88
7.2.00.0030.01016.90
7.1.330.0090.00515.93
7.1.320.0050.01215.84
7.1.310.0030.00915.71
7.1.300.0070.00415.71
7.1.290.0070.00515.79
7.1.280.0040.01015.71
7.1.270.0050.00615.71
7.1.260.0060.00615.84
7.1.250.0030.01415.72
7.1.240.0070.00615.73
7.1.230.0020.00915.77
7.1.220.0070.00715.80
7.1.210.0060.00615.75
7.1.200.0040.00915.92
7.1.190.0030.00815.74
7.1.180.0110.00515.70
7.1.170.0090.00615.88
7.1.160.0040.00915.79
7.1.150.0050.00915.81
7.1.140.0080.00815.95
7.1.130.0050.01115.71
7.1.120.0050.00915.80
7.1.110.0040.00715.63
7.1.100.0030.01115.68
7.1.90.0100.00615.88
7.1.80.0050.00915.71
7.1.70.0100.00216.21
7.1.60.0050.00516.18
7.1.50.0070.01016.13
7.1.40.0050.00915.55
7.1.30.0030.01315.81
7.1.20.0030.00815.79
7.1.10.0090.00115.81
7.1.00.0080.02518.08
7.0.330.0050.00815.38
7.0.320.0080.00515.53
7.0.310.0080.00515.40
7.0.300.0020.00715.30
7.0.290.0030.01015.41
7.0.280.0060.00815.34
7.0.270.0090.00315.33
7.0.260.0070.00515.34
7.0.250.0050.00615.26
7.0.240.0070.01015.50
7.0.230.0040.00715.33
7.0.220.0070.00515.43
7.0.210.0020.01315.41
7.0.200.0050.01016.00
7.0.190.0050.00915.37
7.0.180.0040.01115.39
7.0.170.0130.00315.48
7.0.160.0020.00915.51
7.0.150.0030.01115.46
7.0.140.0050.00715.37
7.0.130.0050.00815.56
7.0.120.0080.00515.54
7.0.110.0070.00715.52
7.0.100.0080.00515.31
7.0.90.0050.00815.36
7.0.80.0090.00415.40
7.0.70.0090.00615.30
7.0.60.0070.03216.89
7.0.50.0060.03416.35
7.0.40.0070.02415.76
7.0.30.0120.01615.66
7.0.20.0190.01715.64
7.0.10.0060.03215.73
7.0.00.0080.03015.73
5.6.400.0060.01314.55
5.6.390.0030.00814.42
5.6.380.0080.00814.24
5.6.370.0110.00314.51
5.6.360.0030.00814.23
5.6.350.0050.01014.38
5.6.340.0050.00814.62
5.6.330.0070.00714.36
5.6.320.0060.00914.57
5.6.310.0060.00614.27
5.6.300.0050.01014.53
5.6.290.0070.00514.36
5.6.280.0050.01916.66
5.6.270.0060.00814.43
5.6.260.0060.00614.38
5.6.250.0070.00714.42
5.6.240.0080.00614.38
5.6.230.0000.01514.58
5.6.220.0080.00514.43
5.6.210.0070.01616.62
5.6.200.0120.01715.67
5.6.190.0070.03316.43
5.6.180.0130.03216.49
5.6.170.0140.03016.43
5.6.160.0060.03316.45
5.6.150.0040.03415.68
5.6.140.0090.02415.61
5.6.130.0070.03015.58
5.6.120.0060.03316.64
5.6.110.0080.03116.61
5.6.100.0020.02316.55
5.6.90.0050.02116.68
5.6.80.0070.02916.47
5.6.70.0050.01114.29
5.6.60.0110.00114.45
5.6.50.0030.00914.13
5.6.40.0080.00814.27
5.6.30.0060.00514.38
5.6.20.0070.00814.38
5.6.10.0030.00914.59
5.6.00.0070.00814.33
5.5.380.0080.00314.45
5.5.370.0060.00914.38
5.5.360.0100.00414.09
5.5.350.0150.03316.28
5.5.340.0030.02315.55
5.5.330.0030.03316.27
5.5.320.0100.02016.36
5.5.310.0080.02316.44
5.5.300.0030.03215.47
5.5.290.0050.02715.67
5.5.280.0050.02116.46
5.5.270.0040.01816.51
5.5.260.0030.03416.39
5.5.250.0120.02416.34
5.5.240.0090.02616.02
5.5.230.0000.01414.22
5.5.220.0060.00614.38
5.5.210.0040.00814.29
5.5.200.0030.01214.21
5.5.190.0090.00514.34
5.5.180.0060.00514.44
5.5.170.0070.00814.29
5.5.160.0100.00714.16
5.5.150.0060.00714.32
5.5.140.0080.00513.94
5.5.130.0090.00914.22
5.5.120.0070.00814.15
5.5.110.0110.00514.24
5.5.100.0070.00714.41
5.5.90.0070.00914.31
5.5.80.0050.01214.32
5.5.70.0060.00714.35
5.5.60.0020.01314.19
5.5.50.0040.01114.17
5.5.40.0070.00714.19
5.5.30.0090.00514.33
5.5.20.0050.00714.41
5.5.10.0080.00514.29
5.5.00.0070.00914.22
5.4.450.0080.02414.59
5.4.440.0080.02214.42
5.4.430.0060.02314.51
5.4.420.0090.02214.61
5.4.410.0090.02414.46
5.4.400.0070.02714.38
5.4.390.0140.01714.24
5.4.380.0110.01714.25
5.4.370.0050.02314.34
5.4.360.0070.02314.40
5.4.350.0070.02114.43
5.4.340.0060.02614.40
5.4.330.0060.00711.99
5.4.320.0070.02414.31
5.4.310.0060.02514.23
5.4.300.0110.02014.51
5.4.290.0090.02214.48
5.4.280.0060.02514.30
5.4.270.0100.01814.42
5.4.260.0040.02514.50
5.4.250.0060.02614.27
5.4.240.0110.01814.29
5.4.230.0090.01914.29
5.4.220.0090.02114.40
5.4.210.0060.02314.46
5.4.200.0110.01814.40
5.4.190.0100.02014.44
5.4.180.0140.02114.39
5.4.170.0090.02014.36
5.4.160.0130.01914.38
5.4.150.0140.01814.40
5.4.140.0110.02313.56
5.4.130.0100.01713.46
5.4.120.0120.01813.40
5.4.110.0090.02013.60
5.4.100.0160.01513.60
5.4.90.0090.02213.48
5.4.80.0100.01913.50
5.4.70.0110.01813.48
5.4.60.0090.02213.60
5.4.50.0070.02213.40
5.4.40.0100.02413.57
5.4.30.0120.01613.57
5.4.20.0070.02413.48
5.4.10.0110.01913.50
5.4.00.0090.02013.27

preferences:
81.18 ms | 403 KiB | 5 Q