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 => '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.0100.01017.76
8.4.10.0130.00717.41
8.3.150.0190.00017.29
8.3.140.0080.00016.73
8.3.130.0030.00716.62
8.3.120.0160.00320.84
8.3.110.0030.00620.94
8.3.100.0060.00318.46
8.3.90.0140.00726.77
8.3.80.0090.00017.97
8.3.70.0070.01416.58
8.3.60.0110.00716.49
8.3.50.0120.00921.99
8.3.40.0090.00619.02
8.3.30.0040.01118.84
8.3.20.0040.00420.34
8.3.10.0080.00023.39
8.3.00.0080.00017.50
8.2.260.0040.00417.32
8.2.250.0040.00418.25
8.2.240.0090.00017.04
8.2.230.0030.00522.58
8.2.220.0000.00824.06
8.2.210.0120.00626.77
8.2.200.0030.00616.50
8.2.190.0130.00316.75
8.2.180.0150.00718.41
8.2.170.0070.01422.96
8.2.160.0100.00320.53
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0110.00319.14
8.2.110.0060.00322.20
8.2.100.0060.00617.78
8.2.90.0050.00317.97
8.2.80.0050.00319.19
8.2.70.0060.00317.48
8.2.60.0050.00317.91
8.2.50.0110.00018.07
8.2.40.0030.00519.40
8.2.30.0030.00320.52
8.2.20.0030.00617.78
8.2.10.0070.00018.19
8.2.00.0040.00418.23
8.1.310.0110.00716.89
8.1.300.0060.01218.34
8.1.290.0050.00530.84
8.1.280.0100.01025.92
8.1.270.0090.00023.84
8.1.260.0110.00726.35
8.1.250.0080.00028.09
8.1.240.0130.00022.07
8.1.230.0110.00022.77
8.1.220.0060.00317.74
8.1.210.0080.00018.98
8.1.200.0030.00617.22
8.1.190.0090.00017.35
8.1.180.0040.00418.10
8.1.170.0080.00018.48
8.1.160.0030.00622.06
8.1.150.0000.00718.96
8.1.140.0000.00819.46
8.1.130.0040.00718.83
8.1.120.0040.00317.49
8.1.110.0000.00717.48
8.1.100.0000.00817.43
8.1.90.0000.00717.36
8.1.80.0040.00417.46
8.1.70.0070.00017.43
8.1.60.0030.00617.60
8.1.50.0040.00817.53
8.1.40.0040.00417.43
8.1.30.0090.00017.64
8.1.20.0030.00517.68
8.1.10.0040.00417.51
8.1.00.0030.00617.54
8.0.300.0000.00720.15
8.0.290.0040.00416.63
8.0.280.0040.00418.45
8.0.270.0000.00717.31
8.0.260.0030.00318.38
8.0.250.0050.00216.86
8.0.240.0060.00316.89
8.0.230.0000.00716.89
8.0.220.0100.00016.84
8.0.210.0070.00016.88
8.0.200.0030.00317.02
8.0.190.0020.00516.85
8.0.180.0030.00516.90
8.0.170.0000.00816.97
8.0.160.0000.00716.95
8.0.150.0040.00416.84
8.0.140.0080.00016.88
8.0.130.0060.00013.37
8.0.120.0080.00016.87
8.0.110.0050.00316.94
8.0.100.0040.00416.91
8.0.90.0040.00416.77
8.0.80.0060.00916.94
8.0.70.0050.00216.70
8.0.60.0040.00416.79
8.0.50.0080.00016.94
8.0.30.0150.00317.05
8.0.20.0130.00817.41
8.0.10.0040.00417.04
8.0.00.0080.01116.80
7.4.330.0030.00315.08
7.4.320.0030.00316.45
7.4.300.0050.00216.50
7.4.290.0000.00716.56
7.4.280.0030.00516.54
7.4.270.0070.00016.59
7.4.260.0000.00716.48
7.4.250.0000.00716.56
7.4.240.0020.00616.48
7.4.230.0000.00716.39
7.4.220.0070.01016.55
7.4.210.0060.00916.48
7.4.200.0000.00716.57
7.4.160.0070.01016.37
7.4.150.0110.00817.40
7.4.140.0190.01117.86
7.4.130.0070.01216.62
7.4.120.0080.01016.47
7.4.110.0150.00416.50
7.4.100.0100.00816.59
7.4.90.0120.00616.61
7.4.80.0070.01719.39
7.4.70.0120.00616.61
7.4.60.0030.01416.46
7.4.50.0030.00616.48
7.4.40.0080.00816.67
7.4.30.0100.00716.51
7.4.00.0060.01214.86
7.3.330.0050.00013.30
7.3.320.0000.00513.45
7.3.310.0000.00716.42
7.3.300.0030.00316.39
7.3.290.0050.01116.36
7.3.280.0120.00816.36
7.3.270.0090.00917.40
7.3.260.0110.00816.61
7.3.250.0090.00716.28
7.3.240.0060.01216.58
7.3.230.0100.00716.39
7.3.210.0090.00616.36
7.3.200.0040.01316.47
7.3.190.0070.01016.67
7.3.180.0060.01116.53
7.3.170.0150.00016.40
7.3.160.0090.00916.57
7.3.120.0060.01014.85
7.3.110.0060.01014.75
7.3.100.0090.00614.90
7.3.90.0050.01014.87
7.3.80.0090.00514.77
7.3.70.0030.01114.76
7.3.60.0050.00814.85
7.3.50.0030.00714.69
7.3.40.0080.00414.80
7.3.30.0090.00514.69
7.3.20.0050.01116.69
7.3.10.0050.00916.59
7.3.00.0090.00716.62
7.2.330.0170.00816.70
7.2.320.0110.00716.72
7.2.310.0110.00616.50
7.2.300.0120.00616.72
7.2.290.0030.01416.70
7.2.250.0090.00815.10
7.2.240.0080.00714.99
7.2.230.0090.00915.15
7.2.220.0040.00915.03
7.2.210.0110.00515.17
7.2.200.0070.00615.15
7.2.190.0050.01114.98
7.2.180.0040.01014.98
7.2.170.0040.01015.10
7.2.160.0060.01015.06
7.2.150.0090.00516.96
7.2.140.0040.01016.88
7.2.130.0040.01116.97
7.2.120.0100.00416.92
7.2.110.0090.00616.88
7.2.100.0080.00516.67
7.2.90.0070.00816.89
7.2.80.0040.00816.80
7.2.70.0070.00816.83
7.2.60.0090.00716.82
7.2.50.0060.00916.76
7.2.40.0070.00916.74
7.2.30.0070.00916.95
7.2.20.0090.00616.92
7.2.10.0080.00716.92
7.2.00.0090.00516.92
7.1.330.0110.00315.78
7.1.320.0090.00615.85
7.1.310.0080.00515.79
7.1.300.0050.00915.74
7.1.290.0030.00815.87
7.1.280.0060.00715.65
7.1.270.0050.01015.69
7.1.260.0060.00915.77
7.1.250.0070.00815.76
7.1.240.0090.00315.56
7.1.230.0040.00415.64
7.1.220.0090.00615.60
7.1.210.0000.01415.75
7.1.200.0030.00815.79
7.1.190.0070.00315.93
7.1.180.0100.00315.74
7.1.170.0120.00315.52
7.1.160.0030.00615.56
7.1.150.0090.00615.58
7.1.140.0060.00915.60
7.1.130.0030.00915.84
7.1.120.0060.00615.86
7.1.110.0000.00915.91
7.1.100.0050.00617.15
7.1.90.0030.00815.74
7.1.80.0040.00415.96
7.1.70.0030.00916.34
7.1.60.0020.01217.64
7.1.50.0090.00816.42
7.1.40.0060.00915.72
7.1.30.0070.00715.57
7.1.20.0040.00715.65
7.1.10.0040.00415.85
7.1.00.0080.03819.03
7.0.330.0000.01515.39
7.0.320.0070.01015.27
7.0.310.0060.00615.39
7.0.300.0030.00615.36
7.0.290.0030.01415.59
7.0.280.0060.00915.26
7.0.270.0000.01415.32
7.0.260.0060.00615.29
7.0.250.0070.00315.48
7.0.240.0070.00715.53
7.0.230.0060.00915.21
7.0.220.0030.01015.39
7.0.210.0040.01115.50
7.0.200.0000.00815.99
7.0.190.0030.00515.24
7.0.180.0140.00315.05
7.0.170.0060.00315.37
7.0.160.0030.01015.24
7.0.150.0070.01015.48
7.0.140.0090.00615.41
7.0.130.0030.00915.48
7.0.120.0000.01215.46
7.0.110.0070.00715.43
7.0.100.0070.01015.14
7.0.90.0000.01315.38
7.0.80.0040.00815.28
7.0.70.0040.00715.18
7.0.60.0050.04217.70
7.0.50.0030.03016.72
7.0.40.0150.02216.65
7.0.30.0120.02216.89
7.0.20.0160.04516.66
7.0.10.0030.05216.83
7.0.00.0070.04316.84
5.6.400.0080.00314.52
5.6.390.0040.01114.53
5.6.380.0100.00714.39
5.6.370.0060.00914.21
5.6.360.0030.01014.56
5.6.350.0090.00614.26
5.6.340.0000.01214.73
5.6.330.0000.00914.61
5.6.320.0030.00714.21
5.6.310.0150.00314.03
5.6.300.0060.00614.75
5.6.290.0030.00714.48
5.6.280.0000.01014.61
5.6.270.0030.01014.13
5.6.260.0040.00814.18
5.6.250.0060.00914.45
5.6.240.0040.00714.46
5.6.230.0070.01114.32
5.6.220.0030.00914.29
5.6.210.0000.05117.58
5.6.200.0070.04416.23
5.6.190.0060.04417.52
5.6.180.0140.02917.65
5.6.170.0170.02717.28
5.6.160.0080.04617.35
5.6.150.0080.04316.38
5.6.140.0070.04316.27
5.6.130.0020.02916.26
5.6.120.0030.04817.69
5.6.110.0060.02917.70
5.6.100.0050.04817.84
5.6.90.0040.02417.69
5.6.80.0070.02217.34
5.6.70.0040.00714.27
5.6.60.0120.00314.27
5.6.50.0100.00314.64
5.6.40.0030.00714.19
5.6.30.0070.01114.32
5.6.20.0000.01314.31
5.6.10.0000.01014.25
5.6.00.0030.01214.25
5.5.380.0070.00714.24
5.5.370.0080.00814.01
5.5.360.0000.01414.65
5.5.350.0160.02017.38
5.5.340.0090.04016.15
5.5.330.0060.04517.23
5.5.320.0120.02517.28
5.5.310.0170.01817.25
5.5.300.0080.04116.12
5.5.290.0080.04516.20
5.5.280.0050.04917.54
5.5.270.0100.03617.46
5.5.260.0060.02517.61
5.5.250.0050.02317.50
5.5.240.0100.03317.18
5.5.230.0030.00914.24
5.5.220.0030.00614.34
5.5.210.0100.00714.43
5.5.200.0090.00314.20
5.5.190.0050.00513.80
5.5.180.0100.00714.37
5.5.170.0060.00913.80
5.5.160.0090.00314.50
5.5.150.0040.00414.32
5.5.140.0110.00414.48
5.5.130.0070.00714.29
5.5.120.0140.00314.17
5.5.110.0120.00414.19
5.5.100.0000.01114.00
5.5.90.0070.00314.04
5.5.80.0060.01013.88
5.5.70.0100.00614.50
5.5.60.0000.00914.41
5.5.50.0080.00414.38
5.5.40.0060.00714.04
5.5.30.0030.00614.23
5.5.20.0100.00714.41
5.5.10.0070.01114.55
5.5.00.0060.00914.47
5.4.450.0250.03215.73
5.4.440.0430.02515.94
5.4.430.0320.03415.79
5.4.420.0350.03215.84
5.4.410.0380.02615.71
5.4.400.0330.03215.75
5.4.390.0370.03015.76
5.4.380.0400.02315.54
5.4.370.0380.03415.54
5.4.360.0330.03315.78
5.4.350.0050.03815.54
5.4.340.0100.02815.81
5.4.330.0080.00312.25
5.4.320.0230.03015.75
5.4.310.0130.02815.63
5.4.300.0100.03815.65
5.4.290.0140.02715.63
5.4.280.0150.04115.81
5.4.270.0080.03415.68
5.4.260.0100.03015.63
5.4.250.0070.03315.65
5.4.240.0120.03415.76
5.4.230.0080.03515.56
5.4.220.0050.03215.81
5.4.210.0130.03015.75
5.4.200.0080.03015.55
5.4.190.0090.02915.68
5.4.180.0120.03015.69
5.4.170.0100.03715.63
5.4.160.0070.02915.62
5.4.150.0230.03515.67
5.4.140.0320.02814.30
5.4.130.0290.02814.41
5.4.120.0440.02214.42
5.4.110.0350.03014.45
5.4.100.0320.03414.47
5.4.90.0030.03314.41
5.4.80.0110.02314.37
5.4.70.0320.03014.28
5.4.60.0300.03614.43
5.4.50.0300.03514.37
5.4.40.0360.03814.40
5.4.30.0360.02714.21
5.4.20.0410.02114.37
5.4.10.0380.02714.41
5.4.00.0300.03114.01

preferences:
37.95 ms | 403 KiB | 5 Q