3v4l.org

run code in 300+ PHP versions simultaneously
<?php function one($s, $p) { return array_intersect_key($s, array_flip($p)); } function two($s, $p) { foreach($s as $key => $value) { if(!array_key_exists($key, $p)) { unset($s[$key]); } } return $s; } function benchmark(callable $function, $args=null, $count=1) { $time = microtime(1); for($i=0; $i<$count; $i++) { $result = is_array($args)? call_user_func_array($function, $args): call_user_func_array($function); } return [ 'total_time' => microtime(1) - $time, 'average_time' => (microtime(1) - $time)/$count, 'count' => $count ]; } $searchParameters = array( 'parameter1' => 'value1', 'parameter2' => 'value2', 'parameter3' => 'value3', ); $allowedParamters = array('parameter1','parameter2'); echo('array_intersect'.PHP_EOL); var_dump(benchmark('one', [$searchParameters, $allowedParamters], 1E6)); echo('foreach'.PHP_EOL); var_dump(benchmark('two', [$searchParameters, $allowedParamters], 1E6));

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)
7.4.10.0131.07814.89
7.4.00.0070.87915.01
7.3.130.0100.91714.93
7.3.120.0071.00514.90
7.3.110.0051.08914.79
7.3.100.0120.79815.03
7.3.90.0051.01214.86
7.3.80.0031.02514.77
7.3.70.0030.94114.97
7.3.60.0031.00914.78
7.3.50.0050.97514.60
7.3.40.0050.97214.84
7.3.30.0050.96214.75
7.3.20.0080.85716.74
7.3.10.0030.95516.61
7.3.00.0030.98116.52
7.2.260.0101.18915.32
7.2.250.0081.08315.17
7.2.240.0101.20514.93
7.2.230.0021.12115.06
7.2.220.0051.20215.24
7.2.210.0050.91315.26
7.2.200.0021.09815.08
7.2.190.0051.13815.00
7.2.180.0031.09014.99
7.2.170.0071.00315.02
7.2.160.0071.05215.23
7.2.150.0030.86417.00
7.2.140.0031.05916.83
7.2.130.0071.11917.05
7.2.120.0030.97817.02
7.2.110.0001.22617.05
7.2.100.0071.22916.99
7.2.90.0031.20817.02
7.2.80.0031.09217.03
7.2.70.0071.13117.01
7.2.60.0110.92417.02
7.2.50.0031.18017.05
7.2.40.0030.89317.00
7.2.30.0030.88316.89
7.2.20.0031.16816.85
7.2.10.0101.19516.97
7.2.00.0080.94218.13
7.1.330.0081.45915.86
7.1.320.0021.66115.89
7.1.310.0051.38015.74
7.1.300.0101.42215.75
7.1.290.0051.46415.76
7.1.280.0071.47415.79
7.1.270.0051.41415.85
7.1.260.0071.49215.76
7.1.250.0001.35315.93
7.1.240.0071.66515.95
7.1.230.0031.63415.58
7.1.220.0031.35415.61
7.1.210.0001.32115.88
7.1.200.0071.30215.54
7.1.190.0001.67115.86
7.1.180.0101.54415.79
7.1.170.0031.29215.79
7.1.160.0031.65815.86
7.1.150.0001.38415.69
7.1.140.0071.61815.70
7.1.130.0031.32815.87
7.1.120.0031.64515.92
7.1.110.0031.60415.93
7.1.100.0071.44515.84
7.1.90.0001.64815.92
7.1.80.0071.60315.79
7.1.70.0001.01716.51
7.1.60.0051.13417.55
7.1.50.0121.13016.17
7.1.40.0031.67315.68
7.1.30.0071.70615.58
7.1.20.0001.71516.00
7.1.10.0031.30315.89
7.1.00.0081.13619.15
7.0.330.0031.60415.48
7.0.320.0101.53215.42
7.0.310.0001.43415.22
7.0.300.0001.65515.41
7.0.290.0031.73815.36
7.0.280.0031.52315.20
7.0.270.0031.74715.41
7.0.260.0071.55215.27
7.0.250.0101.37215.61
7.0.240.0031.70315.44
7.0.230.0101.63015.54
7.0.220.0031.31215.37
7.0.210.0001.54415.36
7.0.200.0031.08916.20
7.0.190.0031.53315.58
7.0.180.0001.42215.39
7.0.170.0031.68215.39
7.0.160.0071.70915.22
7.0.150.0001.56015.36
7.0.140.0031.10518.86
7.0.130.0071.61815.47
7.0.120.0031.62115.44
7.0.110.0001.75415.39
7.0.100.0211.21317.69
7.0.90.0121.09617.66
7.0.80.0101.15017.67
7.0.70.0021.17717.63
7.0.60.0131.22717.73
7.0.50.0071.18317.76
7.0.40.0081.07716.77
7.0.30.0051.17916.79
7.0.20.0101.19016.78
7.0.10.0071.11316.83
7.0.00.0081.07416.80
5.6.400.0002.49914.06
5.6.390.0032.49514.57
5.6.380.0032.49514.39
5.6.370.0002.49814.15
5.6.360.0002.49014.55
5.6.350.0032.49514.02
5.6.340.0002.49714.61
5.6.330.0072.49214.41
5.6.320.0032.49514.40
5.6.310.0032.49514.57
5.6.300.0032.49114.49
5.6.290.0032.49414.27
5.6.280.0052.36617.61
5.6.270.0102.48814.37
5.6.260.0002.49314.51
5.6.250.0122.33817.39
5.6.240.0102.35017.37
5.6.230.0052.30117.49
5.6.220.0052.35917.51
5.6.210.0162.34217.37
5.6.200.0052.47417.68
5.6.190.0032.35917.62
5.6.180.0052.39017.79
5.6.170.0072.47817.62
5.6.160.0052.49517.57
5.6.150.0132.36117.80
5.6.140.0082.35117.87
5.6.130.0072.29617.53
5.6.120.0072.33817.80
5.6.110.0052.33917.73
5.6.100.0052.42317.72
5.6.90.0072.34817.63
5.6.80.0082.35317.41
5.6.70.0052.35917.44
5.6.60.0052.45217.35
5.6.50.0072.34317.54
5.6.40.0072.30917.31
5.6.30.0052.34217.28
5.6.20.0072.34117.27
5.6.10.0032.40117.49
5.6.00.0052.45817.30
5.5.380.0132.40417.41
5.5.370.0032.40117.25
5.5.360.0022.33917.46
5.5.350.0112.45917.44
5.5.340.0052.42217.58
5.5.330.0082.41217.44
5.5.320.0032.49617.65
5.5.310.0072.42017.60
5.5.300.0082.38317.42
5.5.290.0082.43517.56
5.5.280.0072.35217.50
5.5.270.0072.45417.69
5.5.260.0032.34317.53
5.5.250.0032.39517.38
5.5.240.0022.43017.17
5.5.230.0132.47017.19
5.5.220.0052.34717.29
5.5.210.0122.41917.21
5.5.200.0122.32217.19
5.5.190.0052.40217.17
5.5.180.0052.46317.34
5.5.170.0002.49714.16
5.5.160.0082.41917.16
5.5.150.0522.35617.24
5.5.140.0022.40817.16
5.5.130.0072.42717.16
5.5.120.0082.41617.24
5.5.110.0072.44117.29
5.5.100.0052.41917.18
5.5.90.0002.40316.92
5.5.80.0032.39217.13
5.5.70.0102.45317.00
5.5.60.0052.43117.17
5.5.50.0032.44617.24
5.5.40.0082.41717.26
5.5.30.0082.49117.04
5.5.20.0032.42916.96
5.5.10.0072.43117.10
5.5.00.0032.49617.18
5.4.450.0152.46015.60
5.4.440.0052.34415.59
5.4.430.0002.39015.56
5.4.420.0072.35815.73
5.4.410.0022.35215.57
5.4.400.0072.39115.43
5.4.390.0052.36615.39
5.4.380.0102.45615.37
5.4.370.0072.47815.48
5.4.360.0052.34615.50
5.4.350.0052.35915.40
5.4.340.0052.38615.52
5.4.330.0002.49711.90
5.4.320.0212.23715.54
5.4.310.0022.49415.55
5.4.300.0052.34615.46
5.4.290.0022.44915.46
5.4.280.0122.41615.47
5.4.270.0132.40015.53
5.4.260.0032.41815.55
5.4.250.0122.23515.43
5.4.240.0022.29715.38
5.4.230.0022.49815.45
5.4.220.0052.35715.54
5.4.210.0032.43315.47
5.4.200.0022.44915.47
5.4.190.0072.45415.46
5.4.180.0072.36815.51
5.4.170.0072.40415.51
5.4.160.0052.39615.47
5.4.150.0022.31515.46
5.4.140.0082.44114.11
5.4.130.0052.34314.16
5.4.120.0082.41014.16
5.4.110.0072.41914.17
5.4.100.0432.45414.18
5.4.90.0032.33614.23
5.4.80.0082.49114.10
5.4.70.0022.39414.21
5.4.60.0022.43114.13
5.4.50.0052.40114.17
5.4.40.0032.39414.18
5.4.30.0032.42114.10
5.4.20.0032.40914.19
5.4.10.0072.38614.07
5.4.00.0102.46513.82
5.3.290.0000.03813.35
5.3.280.0020.04013.30
5.3.270.0000.03713.27
5.3.260.0020.03813.22
5.3.250.0070.03813.23
5.3.240.0020.04013.28
5.3.230.0050.04013.32
5.3.220.0050.03313.27
5.3.210.0030.02713.27
5.3.200.0050.02013.25
5.3.190.0050.03813.27
5.3.180.0030.03813.20
5.3.170.0000.04613.22
5.3.160.0050.03213.28
5.3.150.0050.04213.22
5.3.140.0050.03713.29
5.3.130.0020.03713.21
5.3.120.0020.04113.21
5.3.110.0030.02213.26
5.3.100.0070.03512.99
5.3.90.0050.03213.00
5.3.80.0050.01712.93
5.3.70.0020.04012.96
5.3.60.0020.03312.92
5.3.50.0050.03212.89
5.3.40.0050.03312.97
5.3.30.0050.03812.86
5.3.20.0020.02212.83
5.3.10.0070.03312.84
5.3.00.0030.02712.78
5.2.170.0070.04011.06
5.2.160.0030.06011.18
5.2.150.0070.03711.08
5.2.140.0070.06011.16
5.2.130.0000.03311.17
5.2.120.0000.02710.96
5.2.110.0070.02311.23
5.2.100.0030.06711.15
5.2.90.0030.06311.04
5.2.80.0030.05011.03
5.2.70.0030.06011.01
5.2.60.0070.06010.99
5.2.50.0030.06311.16
5.2.40.0100.05711.06
5.2.30.0030.05711.09
5.2.20.0100.05311.00
5.2.10.0070.05710.96
5.2.00.0030.03310.63
5.1.60.0070.05010.07
5.1.50.0070.05310.08
5.1.40.0070.0239.89
5.1.30.0070.04310.40
5.1.20.0030.03710.43
5.1.10.0070.04710.17
5.1.00.0070.05010.07
5.0.50.0030.0478.65
5.0.40.0130.0478.44
5.0.30.0070.0508.44
5.0.20.0000.0478.44
5.0.10.0030.0338.44
5.0.00.0030.0608.44
4.4.90.0030.0178.44
4.4.80.0000.0378.44
4.4.70.0000.0208.44
4.4.60.0030.0338.44
4.4.50.0000.0378.44
4.4.40.0100.0438.44
4.4.30.0030.0278.44
4.4.20.0000.0378.44
4.4.10.0000.0308.44
4.4.00.0000.0578.44
4.3.110.0000.0278.44
4.3.100.0030.0208.44
4.3.90.0070.0138.44
4.3.80.0000.0438.44
4.3.70.0000.0338.44
4.3.60.0000.0378.44
4.3.50.0000.0208.44
4.3.40.0030.0278.44
4.3.30.0000.0378.44
4.3.20.0000.0308.44
4.3.10.0000.0208.44
4.3.00.0070.0138.44

preferences:
44 ms | 401 KiB | 5 Q