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 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.10.0460.08137.20
7.3.00.0510.08037.23
7.2.130.0380.09537.29
7.2.120.0610.10236.99
7.2.110.0530.10237.00
7.2.100.0600.09137.06
7.2.90.0680.09937.20
7.2.80.0530.09137.18
7.2.70.0670.10237.12
7.2.60.0720.10137.02
7.2.50.0560.09836.96
7.2.40.0560.08437.11
7.2.30.0640.09436.95
7.2.20.0530.08937.18
7.2.10.0560.09837.07
7.2.00.0530.09537.95
7.1.250.0500.28241.67
7.1.70.0070.14042.93
7.1.60.0070.18743.50
7.1.50.0200.21542.98
7.1.00.0070.26048.45
7.0.200.0070.15142.81
7.0.140.0070.24748.02
7.0.100.0570.21343.28
7.0.90.1100.22342.99
7.0.80.0200.17743.30
7.0.70.1030.17743.34
7.0.60.0200.24343.29
7.0.50.2500.18343.76
7.0.40.1930.21036.19
7.0.30.0600.24736.10
7.0.20.2170.23736.24
7.0.10.1970.23736.22
7.0.00.1970.23736.22
5.6.280.0200.31784.98
5.6.250.0300.25783.14
5.6.240.0370.27783.18
5.6.230.0200.29083.28
5.6.220.0230.25083.23
5.6.210.0270.24383.20
5.6.200.0470.29083.73
5.6.190.0330.30383.79
5.6.180.0370.29783.79
5.6.170.0400.29783.75
5.6.160.0330.37783.62
5.6.150.0300.31783.56
5.6.140.0330.30383.49
5.6.130.0430.29083.79
5.6.120.0270.33783.63
5.6.110.0230.31083.67
5.6.100.0200.31783.65
5.6.90.0370.28083.61
5.6.80.0300.33782.96
5.6.70.0370.30382.98
5.6.60.0300.25083.05
5.6.50.0400.31382.95
5.6.40.0270.27083.00
5.6.30.0370.30782.77
5.6.20.0300.30083.02
5.6.10.0270.29783.01
5.6.00.0230.30782.96
5.5.380.0270.28783.15
5.5.370.0230.28082.99
5.5.360.0200.26783.10
5.5.350.0200.27382.97
5.5.340.0470.25083.39
5.5.330.0230.33383.31
5.5.320.0300.31083.48
5.5.310.0470.29783.41
5.5.300.0370.35083.27
5.5.290.0270.31383.49
5.5.280.0470.29083.43
5.5.270.0400.32383.50
5.5.260.0430.35783.52
5.5.250.0270.26083.25
5.5.240.0270.30082.80
5.5.230.0370.29382.52
5.5.220.0270.31782.89
5.5.210.0470.29382.85
5.5.200.0470.24382.80
5.5.190.0200.34082.63
5.5.180.0270.30082.82
5.5.160.0270.31782.59
5.5.150.0230.30782.76
5.5.140.0330.30782.83
5.5.130.0270.26082.85
5.5.120.0230.31082.78
5.5.110.0170.33782.84
5.5.100.0270.31782.68
5.5.90.0230.26782.74
5.5.80.0230.27783.01
5.5.70.0400.29082.75
5.5.60.0230.31382.52
5.5.50.0200.31082.61
5.5.40.0200.31782.61
5.5.30.0400.32082.71
5.5.20.0470.31082.38
5.5.10.0270.32782.63
5.5.00.0300.32782.50
5.4.450.0200.32382.18
5.4.440.0170.30081.81
5.4.430.0200.35081.80
5.4.420.0370.29081.91
5.4.410.0300.26381.89
5.4.400.0270.31381.62
5.4.390.0370.29781.31
5.4.380.0330.31081.46
5.4.370.0230.26081.50
5.4.360.0430.26781.54
5.4.350.0200.32381.62
5.4.340.0430.25781.24
5.4.320.0130.33081.44
5.4.310.0200.30381.68
5.4.300.0100.28781.61
5.4.290.0330.27781.47
5.4.280.0200.33081.54
5.4.270.0270.33781.59
5.4.260.0300.30081.68
5.4.250.0430.35081.68
5.4.240.0330.24381.61
5.4.230.0270.30081.77
5.4.220.0430.25781.54
5.4.210.0370.31781.38
5.4.200.0530.32381.60
5.4.190.0300.28381.66
5.4.180.0270.31081.35
5.4.170.0170.33381.64
5.4.160.0200.33381.63
5.4.150.0300.31781.38
5.4.140.0270.35379.04
5.4.130.0270.29378.80
5.4.120.0230.35379.07
5.4.110.0300.28078.73
5.4.100.0200.31379.09
5.4.90.0330.31078.83
5.4.80.0400.29779.03
5.4.70.0370.30779.02
5.4.60.0370.30379.07
5.4.50.0270.30078.90
5.4.40.0370.28378.91
5.4.30.0270.28378.93
5.4.20.0300.27378.94
5.4.10.0330.31778.79
5.4.00.0130.32778.48
5.3.290.0300.20076.24
5.3.280.0230.16776.16
5.3.270.0300.17376.21
5.3.260.0400.17376.01
5.3.250.0330.16376.05
5.3.240.0170.17776.08
5.3.230.0300.17376.15
5.3.220.0200.20076.02
5.3.210.0270.19075.99
5.3.200.0270.18375.97
5.3.190.0270.18775.97
5.3.180.0370.17376.03
5.3.170.0270.19076.05
5.3.160.0400.15376.10
5.3.150.0370.20776.07
5.3.140.0100.21376.14
5.3.130.0100.15077.04
5.3.120.0370.17376.11
5.3.110.0500.14776.03
5.3.100.0300.17775.50
5.3.90.0200.17375.41
5.3.80.0300.16775.49
5.3.70.0530.15775.57
5.3.60.0270.19775.44
5.3.50.0230.18775.55
5.3.40.0170.21075.49
5.3.30.0130.16375.31
5.3.20.0270.19075.19
5.3.10.0200.18775.05
5.3.00.0330.13775.19
5.2.170.0070.04011.19
5.2.160.0070.06311.28
5.2.150.0030.03711.20
5.2.140.0030.03011.20
5.2.130.0070.02311.18
5.2.120.0070.02711.17
5.2.110.0000.02711.23
5.2.100.0030.02711.00
5.2.90.0030.02711.13
5.2.80.0030.02711.04
5.2.70.0030.02711.23
5.2.60.0000.03011.19
5.2.50.0030.03311.06
5.2.40.0000.03011.00
5.2.30.0030.04011.05
5.2.20.0000.03011.00
5.2.10.0030.02710.88
5.2.00.0030.03010.65
5.1.60.0030.03710.13
5.1.50.0000.02710.01
5.1.40.0070.02710.08
5.1.30.0000.02710.45
5.1.20.0000.03710.48
5.1.10.0030.04310.08
5.1.00.0000.03310.18
5.0.50.0000.0239.51
5.0.40.0030.0209.51
5.0.30.0030.0439.51
5.0.20.0000.0209.51
5.0.10.0000.0239.51
5.0.00.0000.0309.51
4.4.90.0000.0179.51
4.4.80.0030.0139.51
4.4.70.0000.0179.51
4.4.60.0000.0179.51
4.4.50.0000.0239.51
4.4.40.0030.0209.51
4.4.30.0000.0179.51
4.4.20.0000.0139.51
4.4.10.0000.0209.51
4.4.00.0030.0339.51
4.3.110.0030.0139.51
4.3.100.0000.0179.51
4.3.90.0000.0309.51
4.3.80.0030.0409.51
4.3.70.0030.0179.51
4.3.60.0000.0239.51
4.3.50.0000.0379.51
4.3.40.0000.0309.51
4.3.30.0070.0179.51
4.3.20.0000.0209.51
4.3.10.0000.0139.51
4.3.00.0030.0209.51

preferences:
36.27 ms | 400 KiB | 5 Q