3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('NUMBER_OF_THINGS', 100000); class Something{ const SOME_MAX_VALUE = 100; protected $field; public function setField($value){ $this->field = $value; return $this; } public function getField(){ return $this->field; } } $aBunchOfThings = array(); for($i=0; $i<NUMBER_OF_THINGS; $i++){ $aThing = new Something(); $aBunchOfThings[] = $aThing->setField(rand(1, Something::SOME_MAX_VALUE)); } function searchForeach($array, $needle){ $results = array(); foreach($array as $key => $thing){ if($thing->getField() == $needle){ $result[] = $needle; } } return $result; } function arrayFilterCallback($thing) function searchArrayFilter($array, $needle){ return array_filter($array, function($thing) use ($needle){ return $thing->getField() == $needle; }); } $needle = 50; $start = microtime(true); $result = searchForeach($aBunchOfThings, $needle); $durationForeach = microtime(true) - $start; $start = microtime(true); $result = searchArrayFilter($aBunchOfThings, $needle); $durationArrayFilter = microtime(true) - $start; echo "Function | Time\n"; echo "-----------------------------------------\n"; echo "searchForeach | $durationForeach\n"; echo "searchArrayFilter | $durationArrayFilter\n";

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)
5.4.310.0060.03712.52
5.4.300.0030.03812.53
5.4.290.0060.03812.52
5.4.280.0030.03712.42
5.4.270.0060.03712.42
5.4.260.0080.03512.42
5.4.250.0100.03812.42
5.4.240.0040.03912.42
5.4.230.0050.03912.41
5.4.220.0050.03712.41
5.4.210.0040.03712.41
5.4.200.0070.03712.41
5.4.190.0010.04112.41
5.4.180.0070.03512.41
5.4.170.0030.04412.41
5.4.160.0050.03712.41
5.4.150.0060.03812.40
5.4.140.0070.03612.10
5.4.130.0070.04212.07
5.4.120.0060.04112.04
5.4.110.0090.03612.04
5.4.100.0050.04112.04
5.4.90.0070.03512.04
5.4.80.0080.04012.04
5.4.70.0050.03512.04
5.4.60.0040.03712.04
5.4.50.0030.03912.03
5.4.40.0050.03812.02
5.4.30.0050.03612.02
5.4.20.0060.03712.01
5.4.10.0050.03512.02
5.4.00.0100.03211.50
5.3.280.0090.03412.71
5.3.270.0080.04812.72
5.3.260.0050.04012.72
5.3.250.0060.03812.71
5.3.240.0050.03912.72
5.3.230.0040.04112.71
5.3.220.0060.03712.68
5.3.210.0080.03712.68
5.3.200.0060.03712.68
5.3.190.0040.03912.68
5.3.180.0090.03612.67
5.3.170.0090.03412.67
5.3.160.0080.03512.67
5.3.150.0040.03912.67
5.3.140.0060.03612.66
5.3.130.0070.03712.66
5.3.120.0050.04212.66
5.3.110.0060.04112.65
5.3.100.0070.03712.14
5.3.90.0050.03712.12
5.3.80.0050.04112.11
5.3.70.0060.03912.11
5.3.60.0100.03512.09
5.3.50.0060.04212.04
5.3.40.0070.03612.04
5.3.30.0030.03812.00
5.3.20.0080.03311.78
5.3.10.0020.03811.74
5.3.00.0070.03711.73
5.2.170.0040.0339.23
5.2.160.0040.0319.23
5.2.150.0060.0309.23
5.2.140.0090.0379.23
5.2.130.0040.0309.19
5.2.120.0060.0279.20
5.2.110.0040.0379.19
5.2.100.0030.0309.19
5.2.90.0070.0299.19
5.2.80.0030.0319.19
5.2.70.0050.0339.19
5.2.60.0050.0359.15
5.2.50.0050.0369.11
5.2.40.0010.0359.09
5.2.30.0070.0299.06
5.2.20.0020.0349.05
5.2.10.0050.0288.96
5.2.00.0020.0318.82
5.1.60.0070.0288.11
5.1.50.0060.0238.11
5.1.40.0060.0298.09
5.1.30.0050.0308.44
5.1.20.0050.0278.46
5.1.10.0070.0278.18
5.1.00.0020.0278.18
5.0.50.0040.0276.66
5.0.40.0030.0206.52
5.0.30.0040.0366.33
5.0.20.0030.0206.30
5.0.10.0030.0206.27
5.0.00.0010.0346.27
4.4.90.0030.0184.78
4.4.80.0030.0154.76
4.4.70.0040.0144.75
4.4.60.0040.0154.75
4.4.50.0040.0204.77
4.4.40.0040.0294.70
4.4.30.0040.0154.76
4.4.20.0030.0204.84
4.4.10.0030.0154.85
4.4.00.0010.0324.76
4.3.110.0080.0154.67
4.3.100.0020.0154.66
4.3.90.0050.0124.63
4.3.80.0040.0264.58
4.3.70.0050.0174.63
4.3.60.0020.0204.63
4.3.50.0040.0184.63
4.3.40.0050.0224.54
4.3.30.0020.0153.30
4.3.20.0030.0143.28
4.3.10.0020.0153.23
4.3.00.0070.0237.15

preferences:
146 ms | 1394 KiB | 7 Q