3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** leavecalc Copyright (C) 2014 Paul White This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ //Access every element once using array_filter() $objectArray = []; $objectNames = []; for($i = 0; $i < 1000; $i ++){ $objName = 'object_name_' . ($i + 1); $objectNames[] = $objName; $obj = new stdClass(); $obj->name = $objName; $obj->description = 'test description'; $obj->accessed = 0; $objectArray[] = $obj; } $start = microtime(true); foreach($objectNames as $name){ $iterations = getObjectWithArray_Filter($name, $objectArray); } $end = microtime(true); $taken = $end - $start; echo "Accessing 1000 elements once took " . $iterations . " iterations using array_filter() in $taken seconds<br/>\n"; //Access every element once using foreach(){} $objectArray = []; $objectNames = []; for($i = 0; $i < 1000; $i ++){ $objName = 'object_name_' . ($i + 1); $objectNames[] = $objName; $obj = new stdClass(); $obj->name = $objName; $obj->description = 'test description'; $obj->accessed = 0; $objectArray[] = $obj; } $start = microtime(true); foreach($objectNames as $name){ $iterations = getObjectWithForeach($name, $objectArray); } $end = microtime(true); $taken = $end - $start; echo "Accessing 1000 elements once took " . $iterations . " iterations using foreach(){} in $taken seconds<br/>\n"; //Access every element once using Associative array $objectArray = []; $objectNames = []; for($i = 0; $i < 1000; $i ++){ $objName = 'object_name_' . ($i + 1); $objectNames[] = $objName; $obj = new stdClass(); $obj->name = $objName; $obj->description = 'test description'; $obj->accessed = 0; $objectArray[] = $obj; } $associativeArray = []; $start = microtime(true); foreach($objectArray as $object){ $associativeArray[$object->name] = $object; $object->accessed ++; } foreach($objectNames as $name){ $iterations = getObjectFromAssociativeArray($objName, $associativeArray); } $end = microtime(true); $taken = $end - $start; echo "Accessing 1000 elements once took " . $iterations . " iterations using associative array{} in $taken seconds<br/>\n"; //================================================================= function getObjectWithArray_Filter($objectName, array $objectArray){ $myobjects = array_filter($objectArray, function($e) use($objectName) { $e->accessed ++; return strcmp($e->name, $objectName) == 0; }); $iterations = 0; foreach($objectArray as $object){ $iterations += $object->accessed; } return $iterations; } function getObjectWithForeach($objectName, array $objectArray){ $iterations = 0; $found = false; $count = 0; while(!$found){ $objectArray[$count]->accessed ++; if($objectArray[$count]->name === $objectName){ $found = true; } $count ++; } foreach($objectArray as $object){ $iterations += $object->accessed; } return $iterations; } function getObjectFromAssociativeArray($objectName, array $objectArray){ $iterations = 0; if($objectName === $objectArray[$objectName]->name){ $objectArray[$objectName]->accessed ++; } foreach($objectArray as $object){ $iterations += $object->accessed; } return $iterations; }

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.60.0280.28016.55
7.4.50.0270.28216.93
7.4.40.0260.29016.47
7.4.30.0070.29617.02
7.4.20.0160.29116.31
7.4.10.0120.32716.33
7.4.00.0120.29916.61
7.3.180.0190.29916.72
7.3.170.0090.29416.70
7.3.160.0090.30616.41
7.3.150.0120.28316.67
7.3.140.0130.29416.86
7.3.130.0130.30816.08
7.3.120.0070.35415.71
7.3.110.0110.36916.03
7.3.100.0050.31315.96
7.3.90.0030.30015.94
7.3.80.0110.28415.95
7.3.70.0090.29815.85
7.3.60.0100.32415.76
7.3.50.0060.32015.74
7.3.40.0050.31415.84
7.3.30.0130.27315.83
7.3.20.0150.32016.81
7.3.10.0150.31017.14
7.3.00.0080.29516.91
7.2.310.0190.34516.91
7.2.300.0090.37016.74
7.2.290.0030.34717.20
7.2.280.0060.37616.90
7.2.270.0160.34917.18
7.2.260.0100.35116.39
7.2.250.0060.39116.34
7.2.240.0110.42616.12
7.2.230.0090.39016.10
7.2.220.0040.41316.23
7.2.210.0090.39016.17
7.2.200.0070.37816.06
7.2.190.0060.38616.00
7.2.180.0090.34616.15
7.2.170.0180.37516.04
7.2.160.0050.40616.09
7.2.150.0170.36417.01
7.2.140.0100.36517.44
7.2.130.0090.37017.09
7.2.120.0140.38917.29
7.2.110.0090.40117.20
7.2.100.0100.38217.41
7.2.90.0100.39116.97
7.2.80.0100.40917.19
7.2.70.0120.33717.54
7.2.60.0090.33617.52
7.2.50.0150.39417.48
7.2.40.0100.39517.39
7.2.30.0140.39917.43
7.2.20.0090.34317.53
7.2.10.0080.40317.29
7.2.00.0040.35217.54
7.1.330.0090.61416.17
7.1.320.0050.58016.24
7.1.310.0070.52416.33
7.1.300.0090.56516.34
7.1.290.0070.51216.32
7.1.280.0080.55716.32
7.1.270.0120.54115.90
7.1.260.0060.52716.00
7.1.250.0130.52216.26
7.1.240.0140.47116.62
7.1.230.0220.55816.44
7.1.220.0140.51716.39
7.1.210.0190.50716.53
7.1.200.0180.54816.52
7.1.190.0080.45816.69
7.1.180.0200.54816.76
7.1.170.0080.53216.46
7.1.160.0120.50816.68
7.1.150.0080.60116.22
7.1.140.0130.58016.41
7.1.130.0140.61616.57
7.1.120.0080.56016.57
7.1.110.0130.49816.08
7.1.100.0200.54215.93
7.1.90.0170.59616.00
7.1.80.0160.55016.07
7.1.70.0050.46616.21
7.1.60.0180.46817.06
7.1.50.0240.51022.10
7.1.40.0100.55415.81
7.1.30.0150.53316.09
7.1.20.0160.52716.00
7.1.10.0270.48015.75
7.1.00.0040.49118.20
7.0.330.0080.54016.25
7.0.320.0110.50316.19
7.0.310.0110.51416.20
7.0.300.0060.52416.36
7.0.290.0170.49916.04
7.0.280.0080.59915.97
7.0.270.0190.56716.20
7.0.260.0440.52715.74
7.0.250.0200.54315.51
7.0.240.0170.59515.46
7.0.230.0220.54615.68
7.0.220.0160.47315.43
7.0.210.0150.54815.45
7.0.200.0160.49216.09
7.0.190.0250.51715.60
7.0.180.0190.58515.56
7.0.170.0180.57315.68
7.0.160.0200.57115.52
7.0.150.0110.54415.57
7.0.140.0100.49817.72
7.0.130.0100.49315.80
7.0.120.0140.57415.53
7.0.110.0120.65915.67
7.0.100.0120.61615.50
7.0.90.0140.51515.61
7.0.80.0110.66616.10
7.0.70.0130.61415.96
7.0.60.0090.55317.64
7.0.50.0090.55817.02
7.0.40.0120.49616.31
7.0.30.0100.51216.44
7.0.20.0140.56016.94
7.0.10.0130.53816.60
7.0.00.0150.64116.53
5.6.400.0171.32116.58
5.6.390.0131.34616.53
5.6.380.0431.31916.42
5.6.370.0321.31216.56
5.6.360.0131.22516.53
5.6.350.0191.40116.14
5.6.340.0321.31916.26
5.6.330.0231.40316.48
5.6.320.0371.23616.48
5.6.310.0411.25416.39
5.6.300.0431.24016.16
5.6.290.0321.17816.54
5.6.280.0181.17318.33
5.6.270.0251.36716.56
5.6.260.0211.38416.51
5.6.250.0131.26816.35
5.6.240.0261.36216.12
5.6.230.0101.40016.06
5.6.220.0101.36016.01
5.6.210.0151.24217.96
5.6.200.0131.23317.38
5.6.190.0141.08717.96
5.6.180.0181.10818.02
5.6.170.0151.22317.96
5.6.160.0161.24318.07
5.6.150.0101.06217.38
5.6.140.0151.24917.29
5.6.130.0201.14817.19
5.6.120.0331.18218.10
5.6.110.0191.21218.27
5.6.100.0141.12818.26
5.6.90.0041.23818.27
5.6.80.0161.21817.93
5.6.70.0251.23217.99
5.6.60.0101.45016.30
5.6.50.0211.60716.32
5.6.40.0221.40416.07
5.6.30.0241.32816.05
5.6.20.0111.31616.11
5.6.10.0241.30116.17
5.6.00.0181.34216.21
5.5.380.0131.41016.19
5.5.370.0101.34816.24
5.5.360.0301.28716.28
5.5.350.0291.28918.09
5.5.340.0131.27417.16
5.5.330.0141.35017.82
5.5.320.0211.24717.88
5.5.310.0201.15418.02
5.5.300.0171.26917.24
5.5.290.0191.28917.20
5.5.280.0251.17218.13
5.5.270.0141.34518.18
5.5.260.0111.18718.20
5.5.250.0141.25118.01
5.5.240.0221.25217.82
5.5.230.0161.48616.36
5.5.220.0211.49416.25
5.5.210.0211.29716.21
5.5.200.0221.20116.17
5.5.190.0081.48216.45
5.5.180.0151.51316.21
5.5.170.0381.36416.18
5.5.160.0121.42116.35
5.5.150.0181.41216.41
5.5.140.0191.44816.34
5.5.130.0211.47916.06
5.5.120.0211.49216.44
5.5.110.0161.43516.24
5.5.100.0321.52416.44
5.5.90.0211.29216.37
5.5.80.0031.34516.29
5.5.70.0161.59416.44
5.5.60.0211.37216.07
5.5.50.0171.67516.21
5.5.40.0211.40016.17
5.5.30.0141.44116.22
5.5.20.0291.52616.23
5.5.10.0341.41016.18
5.5.00.0211.29616.20
5.4.450.0191.25115.52
5.4.440.0221.15715.64
5.4.430.0191.29815.50
5.4.420.0181.18415.52
5.4.410.0131.21515.48
5.4.400.0121.10815.45
5.4.390.0211.31915.47
5.4.380.0191.26115.44
5.4.370.0241.12815.47
5.4.360.0081.21315.46
5.4.350.0181.27315.49
5.4.340.0201.12715.47
5.4.330.0331.52413.12
5.4.320.0181.16915.43
5.4.310.0191.19215.48
5.4.300.0141.25515.31
5.4.290.0241.20915.44
5.4.280.0161.11615.41
5.4.270.0221.21415.53
5.4.260.0431.26015.40
5.4.250.0221.15915.34
5.4.240.0271.18415.38
5.4.230.0141.25515.44
5.4.220.0231.28515.37
5.4.210.0271.24015.42
5.4.200.0181.26015.38
5.4.190.0331.31315.41
5.4.180.0261.30115.48
5.4.170.0191.27115.37
5.4.160.0171.13815.44
5.4.150.0111.23515.32
5.4.140.0151.19714.63
5.4.130.0091.18914.56
5.4.120.0091.17614.53
5.4.110.0191.14614.65
5.4.100.0151.09214.56
5.4.90.0131.20314.41
5.4.80.0161.25514.57
5.4.70.0191.17714.49
5.4.60.0121.21614.50
5.4.50.0141.19414.48
5.4.40.0281.19514.56
5.4.30.0121.16814.61
5.4.20.0121.15714.55
5.4.10.0181.18514.48
5.4.00.0141.11714.33
5.3.290.0130.02113.68
5.3.280.0150.03913.55
5.3.270.0140.02813.52
5.3.260.0190.02213.58
5.3.250.0140.02813.69
5.3.240.0060.03013.63
5.3.230.0120.02513.64
5.3.220.0080.02413.69
5.3.210.0130.01813.55
5.3.200.0120.02013.55
5.3.190.0130.01813.61
5.3.180.0150.01813.68
5.3.170.0190.03613.68
5.3.160.0140.03213.56
5.3.150.0150.03213.64
5.3.140.0130.04113.55
5.3.130.0150.03713.62
5.3.120.0270.03313.71
5.3.110.0180.03613.70
5.3.100.0130.04113.30
5.3.90.0120.03313.41
5.3.80.0120.03913.33
5.3.70.0110.03113.38
5.3.60.0100.04313.41
5.3.50.0110.03613.27
5.3.40.0170.02813.30
5.3.30.0130.03913.15
5.3.20.0120.02113.19
5.3.10.0280.02913.08
5.3.00.0130.03012.98
5.2.170.0080.02411.81
5.2.160.0120.03211.87
5.2.150.0060.02811.84
5.2.140.0160.01511.91
5.2.130.0150.03211.82
5.2.120.0170.02311.91
5.2.110.0160.03011.80
5.2.100.0100.03011.91
5.2.90.0100.03211.82
5.2.80.0120.02911.75
5.2.70.0240.01711.77
5.2.60.0100.02211.72
5.2.50.0110.02411.77
5.2.40.0110.02211.79
5.2.30.0110.02111.74
5.2.20.0060.02711.76
5.2.10.0130.02111.72
5.2.00.0110.02011.64
5.1.60.0110.01511.33
5.1.50.0070.02611.33
5.1.40.0100.02711.43
5.1.30.0110.02911.49
5.1.20.0130.02711.44
5.1.10.0130.02111.47
5.1.00.0100.02211.43
5.0.50.0060.02711.01
5.0.40.0060.01911.01
5.0.30.0110.03111.01
5.0.20.0080.02311.01
5.0.10.0060.01511.01
5.0.00.0070.02611.01
4.4.90.0050.02111.01
4.4.80.0080.01711.01
4.4.70.0050.02011.01
4.4.60.0020.02011.01
4.4.50.0060.01011.01
4.4.40.0020.02111.01
4.4.30.0050.01811.01
4.4.20.0100.01511.01
4.4.10.0050.02011.01
4.4.00.0090.01211.01
4.3.110.0050.01611.01
4.3.100.0050.01411.01
4.3.90.0080.00811.01
4.3.80.0050.03111.01
4.3.70.0030.01511.01
4.3.60.0050.01311.01
4.3.50.0060.01211.01
4.3.40.0060.01611.01
4.3.30.0060.01111.01
4.3.20.0030.01011.01
4.3.10.0050.01811.01
4.3.00.0030.01911.01

preferences:
37.33 ms | 400 KiB | 5 Q