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=array(), $count=1) { $time = microtime(1); for($i=0; $i<$count; $i++) { $result = call_user_func_array($function, $args); } 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], 1E5)); echo('foreach'.PHP_EOL); var_dump(benchmark('two', [$searchParameters, $allowedParamters], 1E5));

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.00.0130.10915.02
7.3.120.0070.12015.08
7.3.110.0070.10915.14
7.3.100.0130.07815.13
7.3.90.0070.09515.11
7.3.80.0070.07714.88
7.3.70.0030.07914.78
7.3.60.0070.08914.86
7.3.50.0000.07914.67
7.3.40.0070.07514.71
7.3.30.0000.08414.86
7.3.20.0100.08016.48
7.3.10.0160.07116.70
7.3.00.0030.07416.77
7.2.250.0100.12914.96
7.2.240.0130.12314.79
7.2.230.0070.08715.08
7.2.220.0030.08115.22
7.2.210.0000.10614.96
7.2.200.0070.07715.23
7.2.190.0070.07914.92
7.2.180.0000.09115.11
7.2.170.0070.08015.13
7.1.330.0070.11915.96
7.1.320.0030.13815.87
7.1.310.0070.11916.11
7.1.300.0070.12415.97
7.1.290.0030.13815.89
7.1.280.0070.12516.01
7.1.270.0070.12315.98
7.1.260.0070.12115.77
7.1.70.0030.06517.24
7.1.60.0100.10319.32
7.1.50.0100.10916.95
7.1.00.0070.14722.45
7.0.200.0070.05716.90
7.0.140.0030.15722.00
7.0.110.0530.14019.89
7.0.100.0170.12720.09
7.0.90.0230.14020.02
7.0.80.0100.16019.89
7.0.70.0270.12319.97
7.0.60.0130.18720.06
7.0.50.0130.15020.38
7.0.40.0100.10320.13
7.0.30.0030.08020.00
7.0.20.0000.16720.17
7.0.10.0030.11020.01
7.0.00.0030.15720.11
5.6.280.0070.33321.00
5.6.250.0100.28720.65
5.6.240.0070.29720.52
5.6.230.0030.28320.66
5.6.220.0100.31320.63
5.6.210.0100.29020.35
5.6.200.0130.28721.11
5.6.190.0100.27321.22
5.6.180.0000.25320.98
5.6.170.0070.28020.90
5.6.160.0070.24321.22
5.6.150.0030.33021.10
5.6.140.0070.24021.09
5.6.130.0070.25721.04
5.6.120.0030.29320.84
5.6.110.0030.29721.09
5.6.100.0030.24021.00
5.6.90.0070.28320.99
5.6.80.0100.29720.48
5.6.70.0070.28020.29
5.6.60.0030.28320.45
5.6.50.0070.29720.43
5.6.40.0100.27320.43
5.6.30.0100.29320.39
5.6.20.0000.30020.50
5.6.10.0070.28020.33
5.6.00.0030.30320.25
5.5.380.0100.32020.50
5.5.370.0100.28320.32
5.5.360.0130.32720.49
5.5.350.0130.30320.42
5.5.340.0070.32320.91
5.5.330.0100.27720.86
5.5.320.0000.21720.89
5.5.310.0100.30020.82
5.5.300.0100.33720.77
5.5.290.0030.29320.91
5.5.280.0070.29720.70
5.5.270.0100.22720.90
5.5.260.0100.30720.78
5.5.250.0030.32720.47
5.5.240.0030.32720.08
5.5.230.0000.33020.08
5.5.220.0070.29720.22
5.5.210.0100.29720.18
5.5.200.0000.33720.30
5.5.190.0030.31020.21
5.5.180.0100.31020.12
5.5.160.0100.32720.12
5.5.150.0030.33020.32
5.5.140.0130.30320.27
5.5.130.0030.33320.12
5.5.120.0100.32320.27
5.5.110.0100.30720.21
5.5.100.0100.31720.13
5.5.90.0070.30319.95
5.5.80.0070.31320.16
5.5.70.0070.31019.95
5.5.60.0030.26320.05
5.5.50.0070.29020.02
5.5.40.0100.32319.93
5.5.30.0030.31020.01
5.5.20.0100.30320.17
5.5.10.0030.29320.00
5.5.00.0100.31020.02
5.4.450.0030.27319.32
5.4.440.0000.25719.61
5.4.430.0100.32319.31
5.4.420.0070.26719.31
5.4.410.0070.31019.21
5.4.400.0070.32718.98
5.4.390.0030.28019.00
5.4.380.0030.26318.96
5.4.370.0100.31319.05
5.4.360.0000.29319.16
5.4.350.0230.27319.24
5.4.340.0070.31318.98
5.4.320.0030.31719.14
5.4.310.0070.32719.16
5.4.300.0130.28718.98
5.4.290.0070.31719.09
5.4.280.0000.31018.96
5.4.270.0100.30319.15
5.4.260.0070.31319.16
5.4.250.0100.29719.16
5.4.240.0130.27719.23
5.4.230.0100.31719.30
5.4.220.0030.30719.20
5.4.210.0070.31319.14
5.4.200.0100.30318.94
5.4.190.0130.29719.02
5.4.180.0030.32319.13
5.4.170.0100.32019.29
5.4.160.0030.32018.97
5.4.150.0070.29719.07
5.4.140.0130.29716.38
5.4.130.0100.28716.30
5.4.120.0100.31016.49
5.4.110.0100.33316.62
5.4.100.0000.32716.61
5.4.90.0030.29716.28
5.4.80.0000.31716.63
5.4.70.0130.30316.50
5.4.60.0100.29016.54
5.4.50.0100.29716.53
5.4.40.0070.29316.53
5.4.30.0030.32716.51
5.4.20.0130.31716.39
5.4.10.0030.30316.38
5.4.00.0070.31015.70
5.3.290.0100.07014.70
5.3.280.0070.07714.70
5.3.270.0000.08014.64
5.3.260.0170.06714.63
5.3.250.0070.08314.47
5.3.240.0170.06314.63
5.3.230.0070.06314.75
5.3.220.0130.07014.55
5.3.210.0070.07314.43
5.3.200.0030.07714.57
5.3.190.0070.07714.67
5.3.180.0170.05714.70
5.3.170.0000.07314.70
5.3.160.0070.07714.58
5.3.150.0070.07014.56
5.3.140.0030.05714.57
5.3.130.0130.07314.68
5.3.120.0030.07314.56
5.3.110.0100.07714.69
5.3.100.0070.07714.17
5.3.90.0130.06714.16
5.3.80.0030.07314.00
5.3.70.0130.07014.04
5.3.60.0070.07014.04
5.3.50.0100.04714.09
5.3.40.0000.04314.18
5.3.30.0030.06014.00
5.3.20.0170.04313.70
5.3.10.0100.06013.69
5.3.00.0030.08013.50
5.2.170.0030.03711.22
5.2.160.0100.05711.17
5.2.150.0000.04711.38
5.2.140.0100.05711.23
5.2.130.0070.06011.10
5.2.120.0000.06311.19
5.2.110.0000.06711.19
5.2.100.0000.05311.13
5.2.90.0070.04011.17
5.2.80.0000.04011.20
5.2.70.0070.06011.11
5.2.60.0130.05311.28
5.2.50.0100.05311.11
5.2.40.0070.05710.96
5.2.30.0070.05711.12
5.2.20.0000.06710.82
5.2.10.0130.05311.10
5.2.00.0000.05010.85
5.1.60.0030.0509.96
5.1.50.0030.0309.97
5.1.40.0000.05710.06
5.1.30.0100.05010.20
5.1.20.0030.05310.60
5.1.10.0030.0539.90
5.1.00.0030.0579.92
5.0.50.0000.0479.86
5.0.40.0070.0439.86
5.0.30.0000.0579.86
5.0.20.0030.0309.86
5.0.10.0070.0179.86
5.0.00.0030.0609.86
4.4.90.0070.0309.86
4.4.80.0100.0239.86
4.4.70.0030.0239.86
4.4.60.0030.0179.86
4.4.50.0030.0339.86
4.4.40.0030.0509.86
4.4.30.0000.0379.86
4.4.20.0070.0139.86
4.4.10.0000.0379.86
4.4.00.0030.0479.86
4.3.110.0070.0239.86
4.3.100.0030.0279.86
4.3.90.0000.0339.86
4.3.80.0000.0479.86
4.3.70.0030.0239.86
4.3.60.0030.0339.86
4.3.50.0070.0209.86
4.3.40.0030.0509.86
4.3.30.0000.0339.86
4.3.20.0030.0339.86
4.3.10.0030.0339.86
4.3.00.0000.0379.86

preferences:
35.27 ms | 401 KiB | 5 Q