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'); //set_time_limit(0); 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.00.0030.78014.89
7.3.120.0100.82114.93
7.3.110.0101.15915.11
7.3.100.0100.90914.76
7.3.90.0031.02315.07
7.3.80.0071.04914.88
7.3.70.0030.79614.67
7.3.60.0001.04914.98
7.3.50.0071.09214.55
7.3.40.0030.80815.09
7.3.30.0031.07014.82
7.3.20.0000.94016.69
7.3.10.0030.92416.63
7.3.00.0030.86416.81
7.2.250.0201.23615.26
7.2.240.0071.21515.00
7.2.230.0001.06115.03
7.2.220.0071.04814.69
7.2.210.0071.15715.37
7.2.200.0031.17415.14
7.2.190.0100.83015.10
7.2.180.0000.89415.14
7.2.170.0101.20614.74
7.2.130.0100.82816.88
7.2.120.0030.89417.00
7.2.110.0030.86417.01
7.2.100.0100.87016.91
7.2.90.0030.91217.05
7.2.80.0030.88717.00
7.2.70.0030.83716.93
7.2.60.0030.86016.76
7.2.50.0000.86917.02
7.2.40.0070.84617.06
7.2.30.0030.80717.05
7.2.20.0070.83617.06
7.2.10.0070.81717.09
7.2.00.0020.68218.32
7.1.330.0161.48815.95
7.1.320.0031.65416.04
7.1.310.0001.58315.76
7.1.300.0031.65415.61
7.1.290.0001.33315.70
7.1.280.0001.41015.85
7.1.270.0001.52915.59
7.1.260.0001.21615.87
7.1.250.0101.29415.65
7.1.70.0030.77616.85
7.1.60.0100.62219.32
7.1.50.0100.60816.73
7.1.00.0030.63022.47
7.0.200.0030.59816.84
7.0.140.0130.89022.10
7.0.100.0030.64020.00
7.0.90.0130.72720.01
7.0.80.0070.72019.95
7.0.70.0100.68720.00
7.0.60.0070.73719.97
7.0.50.0270.69320.36
7.0.40.0070.70320.10
7.0.30.0130.77720.04
7.0.20.0000.71320.03
7.0.10.0070.56020.17
7.0.00.0000.56720.11
5.6.280.0032.22021.08
5.6.250.0032.05020.82
5.6.240.0172.48320.58
5.6.230.0072.16720.69
5.6.220.0132.25720.68
5.6.210.0072.18720.57
5.6.200.0102.10721.07
5.6.190.0132.22320.96
5.6.180.0032.26721.09
5.6.170.0072.00321.04
5.6.160.0002.06721.17
5.6.150.0072.14321.01
5.6.140.0002.50020.96
5.6.130.0102.48721.02
5.6.120.0132.09021.14
5.6.110.0072.10321.04
5.6.100.0032.17720.93
5.6.90.0132.09020.95
5.6.80.2272.06020.43
5.6.70.0072.24720.37
5.6.60.0032.02320.39
5.6.50.0132.20720.38
5.6.40.0102.16320.44
5.6.30.0072.22020.39
5.6.20.0072.46320.45
5.6.10.0032.14720.39
5.6.00.0072.18720.29
5.5.380.0032.33720.46
5.5.370.0072.35020.34
5.5.360.0002.35020.44
5.5.350.0202.42020.48
5.5.340.0032.34720.79
5.5.330.0002.45020.92
5.5.320.0102.36320.88
5.5.310.0102.36320.77
5.5.300.0072.27720.78
5.5.290.0032.25020.86
5.5.280.0032.43720.87
5.5.270.0102.43020.96
5.5.260.0102.39020.92
5.5.250.0132.38320.64
5.5.240.0002.38020.31
5.5.230.0072.17720.03
5.5.220.0102.34720.27
5.5.210.0032.21320.30
5.5.200.0072.24020.00
5.5.190.0102.34720.28
5.5.180.0072.38020.14
5.5.160.0102.49020.12
5.5.150.0132.36320.15
5.5.140.0102.42020.23
5.5.130.0002.22720.00
5.5.120.0072.36320.13
5.5.110.0072.40320.00
5.5.100.0072.32720.08
5.5.90.0002.47319.96
5.5.80.0032.29020.16
5.5.70.0102.42019.97
5.5.60.0002.22320.07
5.5.50.0132.48720.15
5.5.40.0072.34020.08
5.5.30.0032.35720.11
5.5.20.0032.29319.94
5.5.10.0202.38020.12
5.5.00.0172.36320.12
5.4.450.0032.35319.38
5.4.440.0102.34019.54
5.4.430.0072.49319.11
5.4.420.0102.47019.55
5.4.410.0032.38019.32
5.4.400.0102.36719.21
5.4.390.0032.16019.05
5.4.380.0032.23018.87
5.4.370.0102.34719.18
5.4.360.0102.37719.11
5.4.350.0032.42318.88
5.4.340.0032.34319.22
5.4.320.0032.25319.23
5.4.310.0132.33719.07
5.4.300.0002.36019.03
5.4.290.0072.23319.13
5.4.280.0032.35019.00
5.4.270.0072.39719.20
5.4.260.0032.34719.04
5.4.250.0232.39318.85
5.4.240.0032.49719.07
5.4.230.0002.37018.94
5.4.220.0032.24719.22
5.4.210.0002.34719.20
5.4.200.0032.36718.89
5.4.190.0072.49319.02
5.4.180.0072.36319.04
5.4.170.0032.32319.02
5.4.160.0002.36719.07
5.4.150.0072.31019.19
5.4.140.0102.29016.50
5.4.130.0072.26016.46
5.4.120.0002.34016.50
5.4.110.0102.33016.55
5.4.100.0072.39016.52
5.4.90.0002.39316.48
5.4.80.0102.37716.54
5.4.70.0132.36316.54
5.4.60.0172.42716.47
5.4.50.0102.35016.32
5.4.40.0072.30716.37
5.4.30.0172.32016.49
5.4.20.0032.33016.39
5.4.10.0072.22716.32
5.4.00.0072.21715.78
5.3.290.0130.06314.79
5.3.280.0000.04014.66
5.3.270.0000.03314.70
5.3.260.0070.04314.54
5.3.250.0070.05314.58
5.3.240.0070.05714.72
5.3.230.0030.07714.58
5.3.220.0170.04714.73
5.3.210.0130.06014.50
5.3.200.0070.08014.52
5.3.190.0100.05714.63
5.3.180.0070.06314.70
5.3.170.0030.07714.65
5.3.160.0070.03014.59
5.3.150.0100.07314.63
5.3.140.0130.07714.51
5.3.130.0000.08314.52
5.3.120.0100.04314.48
5.3.110.0100.08314.64
5.3.100.0070.08014.00
5.3.90.0070.03713.96
5.3.80.0130.05314.04
5.3.70.0130.06714.02
5.3.60.0030.06013.91
5.3.50.0100.03314.08
5.3.40.0000.04314.02
5.3.30.0070.07013.84
5.3.20.0030.04013.75
5.3.10.0000.04713.77
5.3.00.0100.05313.75
5.2.170.0000.04012.31
5.2.160.0070.06012.31
5.2.150.0070.04312.31
5.2.140.0030.06312.31
5.2.130.0130.05312.31
5.2.120.0100.02712.31
5.2.110.0030.06312.31
5.2.100.0070.05312.31
5.2.90.0030.03312.31
5.2.80.0130.05312.31
5.2.70.0170.05312.31
5.2.60.0100.05312.31
5.2.50.0100.06012.31
5.2.40.0030.04712.31
5.2.30.0030.06012.31
5.2.20.0030.04712.31
5.2.10.0000.06312.31
5.2.00.0000.04012.31
5.1.60.0000.03012.31
5.1.50.0100.02712.31
5.1.40.0030.05312.31
5.1.30.0070.02712.31
5.1.20.0070.05712.31
5.1.10.0030.06012.31
5.1.00.0030.05312.31
5.0.50.0070.04712.31
5.0.40.0030.04312.31
5.0.30.0030.05712.31
5.0.20.0070.04012.31
5.0.10.0000.05012.31
5.0.00.0070.04312.31
4.4.90.0000.03012.31
4.4.80.0000.03712.31
4.4.70.0000.04012.31
4.4.60.0070.02712.31
4.4.50.0030.02712.31
4.4.40.0000.04712.31
4.4.30.0030.02312.31
4.4.20.0070.03012.31
4.4.10.0030.03012.31
4.4.00.0070.05012.31
4.3.110.0000.02312.31
4.3.100.0000.03312.31
4.3.90.0030.03012.31
4.3.80.0070.04312.31
4.3.70.0030.02712.31
4.3.60.0000.03712.31
4.3.50.0030.02712.31
4.3.40.0030.02712.31
4.3.30.0000.03712.31
4.3.20.0030.01712.31
4.3.10.0100.03012.31
4.3.00.0000.03712.31

preferences:
37.96 ms | 401 KiB | 5 Q