3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('NUMBER_OF_THINGS', 10000); 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 searchArrayFilter($array, $needle){ return array_filter($array, function(&$thing) use (&$needle){ return $thing->getField() == $needle; }); } function uniqueForeach($array){ $results = array(); foreach($array as $key => $thing){ $uniqueThing = true; foreach($results as $result){ if($result->getField() == $thing->getField()){ $uniqueThing = false; break; } } if($uniqueThing){ $result[] = $thing; } } return $result; } function uniqueArrayMap($array){ return array_intersect_key($array, array_unique(array_map(function (&$thing) { return $thing->getField(); }, $array))); } $needle = 50; $start = microtime(true); $result = searchForeach($aBunchOfThings, $needle); $durationForeach = microtime(true) - $start; $start = microtime(true); $result = searchArrayFilter($aBunchOfThings, $needle); $durationArrayFilter = microtime(true) - $start; $start = microtime(true); $result = uniqueForeach($aBunchOfThings); $durationUniqueForeach = microtime(true) - $start; $start = microtime(true); $result = uniqueArrayMap($aBunchOfThings); $durationUniqueArrayMap = microtime(true) - $start; echo "Function | Time\n"; echo "-----------------------------------------\n"; echo "searchForeach | $durationForeach\n"; echo "searchArrayFilter | $durationArrayFilter\n"; echo "uniqueForeach | $durationUniqueForeach\n"; echo "uniqueArrayMap | $durationUniqueArrayMap\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)
7.3.120.0040.01816.48
7.3.110.0100.01316.69
7.3.100.0070.01016.78
7.3.90.0000.01916.83
7.3.80.0070.01616.67
7.3.70.0120.01216.59
7.3.60.0100.01016.63
7.3.50.0060.01316.55
7.3.40.0040.01816.23
7.3.30.0090.01216.55
7.3.20.0030.01618.61
7.3.10.0090.01218.57
7.3.00.0090.01218.54
7.2.240.0090.01617.02
7.2.230.0000.02417.09
7.2.220.0070.01716.84
7.2.210.0150.01217.22
7.2.200.0030.02316.97
7.2.190.0070.01616.97
7.2.180.0090.02216.81
7.2.170.0030.02316.75
7.2.160.0100.01317.09
7.2.150.0060.01619.09
7.2.140.0000.02019.13
7.2.130.0020.01819.33
7.2.120.0030.01919.14
7.2.110.0050.01619.14
7.2.100.0050.01418.93
7.2.90.0020.02119.29
7.2.80.0060.01319.21
7.2.70.0020.02119.15
7.2.60.0020.02519.13
7.2.50.0060.02018.83
7.2.40.0080.01419.08
7.2.30.0050.02119.26
7.2.20.0080.01219.21
7.2.10.0080.01519.18
7.2.00.0030.01919.97
7.1.330.0000.03718.14
7.1.320.0070.02617.98
7.1.310.0030.03118.21
7.1.300.0090.03118.05
7.1.290.0000.04318.26
7.1.280.0100.03318.12
7.1.270.0100.02318.11
7.1.260.0030.03017.94
7.1.250.0080.02418.22
7.1.70.0000.01919.40
7.1.60.0100.03719.64
7.1.50.0200.02519.42
7.1.00.0070.09324.52
7.0.200.0030.01719.03
7.0.140.0030.09024.40
7.0.80.0170.05322.77
7.0.70.0230.09022.84
7.0.60.0030.09322.71
7.0.50.1000.08023.02
7.0.40.0070.09720.23
7.0.30.0100.07720.25
7.0.20.0100.08720.31
7.0.10.0030.11320.34
7.0.00.0070.10720.31
5.6.280.0030.13728.19
5.6.230.0130.08727.82
5.6.220.0100.13727.85
5.6.210.0100.08327.69
5.6.200.0170.12328.25
5.6.190.0100.07728.24
5.6.180.0100.14328.12
5.6.170.0170.12028.16
5.6.160.0130.14028.24
5.6.150.0000.09728.29
5.6.140.0070.13728.22
5.6.130.0070.10028.15
5.6.120.0170.10728.24
5.6.110.0130.14028.36
5.6.100.0100.12728.19
5.6.90.0030.13028.29
5.6.80.0130.10327.62
5.6.70.0170.11727.60
5.6.60.0270.11727.67
5.6.50.0200.11327.62
5.6.40.0170.11727.68
5.6.30.0130.09727.60
5.6.20.0200.13327.66
5.6.10.0130.12027.61
5.6.00.0000.12327.56
5.5.370.0170.11727.71
5.5.360.0170.13027.61
5.5.350.0130.14027.66
5.5.340.0000.10328.03
5.5.330.0100.12728.13
5.5.320.0030.13028.01
5.5.310.0030.13327.99
5.5.300.0130.12028.00
5.5.290.0030.11327.93
5.5.280.0030.08328.02
5.5.270.0170.14328.11
5.5.260.0070.12328.11
5.5.250.0200.11727.92
5.5.240.0000.13027.47
5.5.230.0170.12027.49
5.5.220.0100.11027.49
5.5.210.0200.11727.18
5.5.200.0200.12727.30
5.5.190.0130.14027.35
5.5.180.0130.07327.40
5.5.160.0070.12727.46
5.5.150.0070.14327.37
5.5.140.0170.09727.40
5.5.130.0030.10327.30
5.5.120.0030.10027.41
5.5.110.0130.08727.45
5.5.100.0170.12027.16
5.5.90.0070.13727.32
5.5.80.0170.11727.35
5.5.70.0000.09327.30
5.5.60.0170.06727.22
5.5.50.0030.10727.23
5.5.40.0100.07327.13
5.5.30.0130.10327.35
5.5.20.0100.10027.15
5.5.10.0100.09027.23
5.5.00.0070.08327.25
5.4.450.0130.12026.64
5.4.440.0100.12726.45
5.4.430.0100.10326.49
5.4.420.0070.13326.30
5.4.410.0030.10726.34
5.4.400.0100.13026.11
5.4.390.0130.12026.18
5.4.380.0070.07726.34
5.4.370.0100.10326.16
5.4.360.0130.13326.18
5.4.350.0170.11726.03
5.4.340.0170.11726.18
5.4.320.0130.07326.18
5.4.310.0070.12026.12
5.4.300.0200.13026.24
5.4.290.0030.12726.16
5.4.280.0130.11726.26
5.4.270.0130.13026.02
5.4.260.0100.12326.02
5.4.250.0170.11026.21
5.4.240.0000.08026.33
5.4.230.0030.08326.23
5.4.220.0100.11726.02
5.4.210.0030.09326.14
5.4.200.0100.07026.01
5.4.190.0030.08726.01
5.4.180.0030.08726.22
5.4.170.0030.07726.33
5.4.160.0030.07026.14
5.4.150.0070.08026.29
5.4.140.0070.07023.52
5.4.130.0030.07723.57
5.4.120.0000.06723.59
5.4.110.0070.07023.65
5.4.100.0070.11323.46
5.4.90.0100.06723.65
5.4.80.0070.11323.63
5.4.70.0100.10323.65
5.4.60.0000.07323.54
5.4.50.0100.06723.46
5.4.40.0070.07323.52
5.4.30.0070.11723.64
5.4.20.0100.11323.42
5.4.10.0130.12723.41
5.4.00.0130.10323.07
5.3.290.0100.14723.80
5.3.280.0130.08323.82
5.3.270.0030.08323.79
5.3.260.0070.12323.69
5.3.250.0030.08323.79
5.3.240.0070.08023.83
5.3.230.0030.08723.77
5.3.220.0070.09023.68
5.3.210.0000.09323.60
5.3.200.0000.08723.74
5.3.190.0070.07723.60
5.3.180.0100.09323.71
5.3.170.0030.08723.59
5.3.160.0070.10023.77
5.3.150.0030.11323.71
5.3.140.0030.08723.59
5.3.130.0170.13023.73
5.3.120.0070.12323.73
5.3.110.0100.15323.58
5.3.100.0100.12323.16
5.3.90.0200.12723.19
5.3.80.0030.14023.23
5.3.70.0100.12723.15
5.3.60.0170.12723.03
5.3.50.0100.09722.99
5.3.40.0130.14323.12
5.3.30.0170.13322.94
5.3.20.0130.08722.84
5.3.10.0100.15722.77
5.3.00.0070.14322.66
5.2.170.0100.06011.66
5.2.160.0030.06011.66
5.2.150.0170.05311.66
5.2.140.0000.06711.66
5.2.130.0070.05711.66
5.2.120.0000.05711.66
5.2.110.0000.05711.66
5.2.100.0000.06311.66
5.2.90.0100.05711.66
5.2.80.0070.05311.66
5.2.70.0070.06011.66
5.2.60.0000.04711.66
5.2.50.0070.06011.66
5.2.40.0030.04311.66
5.2.30.0030.03711.66
5.2.20.0000.05711.66
5.2.10.0030.06311.66
5.2.00.0000.06711.66
5.1.60.0000.05011.66
5.1.50.0000.03311.66
5.1.40.0070.03311.66
5.1.30.0000.04711.66
5.1.20.0030.05011.66
5.1.10.0030.04011.66
5.1.00.0030.03311.66
5.0.50.0030.03311.66
5.0.40.0030.03711.66
5.0.30.0030.06011.66
5.0.20.0070.03711.66
5.0.10.0030.04311.66
5.0.00.0030.05711.66
4.4.90.0000.04011.66
4.4.80.0000.03711.66
4.4.70.0000.03711.66
4.4.60.0070.03311.66
4.4.50.0000.03711.66
4.4.40.0000.03711.66
4.4.30.0030.02311.66
4.4.20.0000.03711.66
4.4.10.0030.02011.66
4.4.00.0000.04311.66
4.3.110.0070.02011.66
4.3.100.0070.03011.66
4.3.90.0000.03311.66
4.3.80.0030.05011.66
4.3.70.0000.03711.66
4.3.60.0030.03011.66
4.3.50.0100.02011.66
4.3.40.0100.04311.66
4.3.30.0030.03311.66
4.3.20.0030.03311.66
4.3.10.0070.03011.66
4.3.00.0000.03711.66

preferences:
39.2 ms | 401 KiB | 5 Q