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], 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.1.00.0030.62322.38
7.0.140.0070.62722.15
5.4.450.3402.15719.55
5.4.410.3172.16319.28
5.4.400.0002.20019.23
5.4.390.0032.16319.00
5.4.380.1372.19018.99
5.4.340.3002.18019.25
5.4.280.3372.12319.21
5.4.260.0102.21019.22
5.4.250.0072.21019.13
5.4.240.3302.14319.13
5.4.230.3602.12319.18
5.4.220.4002.09718.93
5.4.210.3132.15719.15
5.4.200.0132.44319.05
5.4.190.0272.34018.87
5.4.180.3402.16019.15
5.4.170.3102.15319.21
5.4.160.3832.11319.02
5.4.150.3932.10318.88
5.4.140.0002.24016.45
5.4.130.2002.19016.45
5.4.120.2532.21016.38
5.4.110.0002.21016.61
5.4.100.0172.44316.52
5.4.90.1902.30716.26
5.4.80.3032.12016.22
5.4.70.3372.10716.59
5.4.60.0272.35316.54
5.4.50.3232.11316.38
5.4.40.3872.11016.39
5.4.30.3932.10316.41
5.4.20.3272.14016.25
5.4.10.3932.10316.22
5.4.00.0102.47715.91
5.3.280.3930.04014.60
5.3.270.3430.04314.53
5.3.260.4100.03714.62
5.3.250.0030.08014.68
5.3.240.0000.06014.83
5.3.230.3500.03714.51
5.3.220.2800.04014.62
5.3.210.2800.03314.80
5.3.200.0000.04014.48
5.3.190.3470.03314.64
5.3.180.3630.03714.57
5.3.170.3500.04014.79
5.3.160.3670.03314.48
5.3.150.3130.03314.64
5.3.140.3070.04014.47
5.3.130.3600.04014.71
5.3.120.3430.03714.53
5.3.110.3270.03014.46
5.3.100.3730.04314.04
5.3.90.3330.02714.04
5.3.80.3100.03314.25
5.3.70.3230.03314.11
5.3.60.3130.03314.01
5.3.50.3200.04314.11
5.3.40.3900.04013.86
5.3.30.4770.03013.82
5.3.20.3630.03013.71
5.3.10.3900.04313.68
5.3.00.3800.03713.69

preferences:
31.37 ms | 400 KiB | 5 Q