3v4l.org

run code in 300+ PHP versions simultaneously
<?php //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; } foreach($objectNames as $name){ $iterations = getObjectWithArray_Filter($name, $objectArray); } echo $iterations . " iterations using array_filter()<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; } foreach($objectNames as $name){ $iterations = getObjectWithForeach($name, $objectArray); } echo $iterations . " iterations using foreach(){}<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 = []; foreach($objectArray as $object){ $associativeArray[$object->name] = $object; $object->accessed ++; } foreach($objectNames as $name){ $iterations = getObjectFromAssociativeArray($objName, $associativeArray); } echo $iterations . " iterations using associative array{}<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; }

Abusive script

This script was stopped while abusing our resources

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.0150.30017.03
7.4.50.0110.27617.09
7.4.40.0130.28418.81
7.4.30.0230.28817.12
7.4.20.0190.29217.01
7.4.10.0290.28217.17
7.4.00.0120.34216.56
7.3.180.0190.32017.06
7.3.170.0130.31116.95
7.3.160.0100.30117.18
7.3.150.0270.27817.13
7.3.140.0160.32617.07
7.3.130.0130.28917.05
7.3.120.0170.35115.90
7.3.110.0100.33516.30
7.3.100.0070.30716.00
7.3.90.0150.33716.35
7.3.80.0120.35516.35
7.3.70.0110.29916.15
7.3.60.0160.35216.23
7.3.50.0120.29416.18
7.3.40.0170.28116.08
7.3.30.0110.31416.19
7.3.20.0080.33717.33
7.3.10.0060.31917.40
7.3.00.0110.27617.53
7.2.310.0250.40017.15
7.2.300.0220.33217.35
7.2.290.0200.34517.25
7.2.280.0200.33617.29
7.2.270.0260.33917.00
7.2.260.0060.34716.94
7.2.250.0160.33816.99
7.2.240.0110.36016.20
7.2.230.0100.35416.50
7.2.220.0100.43216.62
7.2.210.0170.45316.46
7.2.200.0130.39316.51
7.2.190.0190.41816.55
7.2.180.0100.35516.43
7.2.170.0080.42316.31
7.2.160.0050.42116.31
7.2.150.0110.36217.76
7.2.140.0050.36817.74
7.2.130.0130.41417.68
7.2.120.0080.36717.67
7.2.110.0170.42917.69
7.2.100.0190.37017.75
7.2.90.0130.37917.56
7.2.80.0160.39917.74
7.2.70.0100.37917.61
7.2.60.0140.31317.29
7.2.50.0170.38617.52
7.2.40.0100.36817.55
7.2.30.0070.33917.42
7.2.20.0150.37417.27
7.2.10.0170.41017.26
7.2.00.0090.32218.29
7.1.330.0150.46516.70
7.1.320.0100.50216.53
7.1.310.0130.49916.51
7.1.300.0210.57616.64
7.1.290.0150.54216.63
7.1.280.0080.56816.80
7.1.270.0130.47016.71
7.1.260.0070.53016.71
7.1.250.0130.50416.68
7.1.240.0060.41817.36
7.1.230.0290.45117.34
7.1.220.0250.46917.33
7.1.210.0340.40017.45
7.1.200.0160.33816.50
7.1.190.0120.40017.41
7.1.180.0230.54817.48
7.1.170.0060.45117.41
7.1.160.0100.40317.27
7.1.150.0170.42417.34
7.1.140.0340.42317.46
7.1.130.0290.43917.52
7.1.120.0260.41817.23
7.1.110.0390.37217.50
7.1.100.0050.35117.87
7.1.90.0030.42617.46
7.1.80.0130.40817.39
7.1.70.0140.35817.17
7.1.60.0160.46218.45
7.1.50.0080.34617.29
7.1.40.0160.39917.44
7.1.30.0320.39417.39
7.1.20.0320.43417.52
7.1.10.0550.46217.35
7.1.00.0110.40519.96
7.0.330.0100.43016.98
7.0.320.0290.39817.23
7.0.310.0170.40617.26
7.0.300.0130.43217.15
7.0.290.0190.42717.02
7.0.280.0370.40416.96
7.0.270.0300.42817.23
7.0.260.0400.43017.19
7.0.250.0100.43717.06
7.0.240.0100.41217.32
7.0.230.0190.50817.02
7.0.220.0150.40517.08
7.0.210.0190.41117.16
7.0.200.0100.35316.95
7.0.190.0200.42817.06
7.0.180.0160.41817.25
7.0.170.0240.41417.12
7.0.160.0330.40417.24
7.0.150.0320.41317.11
7.0.140.0200.42919.54
7.0.130.0070.41416.99
7.0.120.0100.47417.03
7.0.110.0130.46117.13
7.0.100.0190.42317.20
7.0.90.0130.39817.13
7.0.80.0300.47317.10
7.0.70.0250.42517.16
7.0.60.0080.40219.44
7.0.50.0140.46219.58
7.0.40.0080.43618.53
7.0.30.0210.46618.62
7.0.20.0130.42618.57
7.0.10.0110.46518.56
7.0.00.0100.47918.61
5.6.400.0261.08917.38
5.6.390.0261.14217.32
5.6.380.0541.17216.99
5.6.370.0331.18417.27
5.6.360.0351.17617.05
5.6.350.0391.71017.16
5.6.340.0321.26417.47
5.6.330.0291.12017.38
5.6.320.0391.09616.91
5.6.310.0231.05317.28
5.6.300.0271.11417.37
5.6.290.0291.16817.22
5.6.280.0141.12219.66
5.6.270.0191.16817.32
5.6.260.0261.13616.96
5.6.250.0161.42417.29
5.6.240.0511.05817.21
5.6.230.0391.15317.06
5.6.220.0231.07917.09
5.6.210.0321.03719.34
5.6.200.0160.95319.72
5.6.190.0190.95819.59
5.6.180.0191.03719.61
5.6.170.0280.98319.54
5.6.160.0340.91019.77
5.6.150.0181.18119.71
5.6.140.0080.95819.63
5.6.130.0100.90119.71
5.6.120.0160.98819.63
5.6.110.0211.00919.51
5.6.100.0290.94919.83
5.6.90.0110.96819.63
5.6.80.0210.98019.20
5.6.70.0160.99719.29
5.6.60.0110.95419.25
5.6.50.0180.88519.22
5.6.40.0200.93619.38
5.6.30.0210.90519.24
5.6.20.0281.01519.23
5.6.10.0250.91019.30
5.6.00.0070.91219.19
5.5.380.0261.12217.07
5.5.370.0331.09417.06
5.5.360.0641.18917.04
5.5.350.0131.03619.41
5.5.340.0111.03519.47
5.5.330.0240.97119.52
5.5.320.0391.27519.46
5.5.310.0261.05719.45
5.5.300.0190.99719.57
5.5.290.0181.06319.68
5.5.280.0210.90119.50
5.5.270.0151.00619.43
5.5.260.0111.01619.49
5.5.250.0130.97219.39
5.5.240.0221.01719.24
5.5.230.0211.05219.16
5.5.220.0211.01819.12
5.5.210.0231.03419.09
5.5.200.0130.86719.20
5.5.190.0190.91519.17
5.5.180.0181.17219.05
5.5.170.0221.74517.15
5.5.160.0110.98219.03
5.5.150.0071.01619.27
5.5.140.0111.05819.19
5.5.130.0150.93719.32
5.5.120.0171.07919.14
5.5.110.0211.04919.21
5.5.100.0150.98319.12
5.5.90.0250.89219.10
5.5.80.0190.84919.23
5.5.70.0160.96319.20
5.5.60.0061.02619.20
5.5.50.0070.96919.07
5.5.40.0130.91619.00
5.5.30.0091.02519.12
5.5.20.0150.98919.17
5.5.10.0240.88319.15
5.5.00.0070.88021.08
5.4.450.0201.00017.04
5.4.440.0181.01717.03
5.4.430.0190.90417.14
5.4.420.0180.98917.08
5.4.410.0130.96116.97
5.4.400.0251.01516.88
5.4.390.0130.99816.83
5.4.380.0181.19516.88
5.4.370.0211.05016.87
5.4.360.0110.99616.92
5.4.350.0210.95516.90
5.4.340.0180.90117.03
5.4.330.0161.23313.95
5.4.320.0150.99417.14
5.4.310.0100.98416.88
5.4.300.0051.06916.89
5.4.290.0190.98316.88
5.4.280.0251.10917.02
5.4.270.0100.99517.00
5.4.260.0201.00017.01
5.4.250.0170.89616.79
5.4.240.0081.00016.86
5.4.230.0130.94317.00
5.4.220.0181.04716.90
5.4.210.0121.02016.99
5.4.200.0110.94216.94
5.4.190.0140.89117.09
5.4.180.0130.95316.86
5.4.170.0070.85020.06
5.4.160.0000.85319.89
5.4.150.0000.64720.11
5.4.140.0070.88017.36
5.4.130.0000.80717.44
5.4.120.0030.81317.48
5.4.110.0130.82017.45
5.4.100.0100.87017.42
5.4.90.0030.89017.46
5.4.80.0030.91317.38
5.4.70.0030.85317.46
5.4.60.0030.87317.29
5.4.50.0000.83717.38
5.4.40.0000.90317.53
5.4.30.0100.81017.45
5.4.20.0000.85017.31
5.4.10.0000.84017.37
5.4.00.0070.84316.84
5.3.290.0030.04513.69
5.3.280.0080.03813.57
5.3.270.0060.04413.55
5.3.260.0030.08014.54
5.3.250.0000.04014.52
5.3.240.0070.07314.53
5.3.230.0100.03714.52
5.3.220.0030.07314.54
5.3.210.0000.06714.55
5.3.200.0030.07014.48
5.3.190.0070.07314.46
5.3.180.0030.07014.54
5.3.170.0030.06314.54
5.3.160.0000.07714.54
5.3.150.0070.05714.38
5.3.140.0070.04714.38
5.3.130.0030.08014.45
5.3.120.0070.06714.50
5.3.110.0000.03714.34
5.3.100.0100.06314.03
5.3.90.0030.04313.97
5.3.80.0170.06713.95
5.3.70.0100.06314.00
5.3.60.0000.04313.97
5.3.50.0030.04313.91
5.3.40.0030.05313.80
5.3.30.0000.07013.76
5.3.20.0070.07013.59
5.3.10.0130.06313.63
5.3.00.0070.06313.63
5.2.170.0000.06011.11
5.2.160.0000.06710.93
5.2.150.0030.05711.13
5.2.140.0070.04011.14
5.2.130.0000.05710.88
5.2.120.0100.05311.04
5.2.110.0030.05311.11
5.2.100.0000.06710.93
5.2.90.0030.05311.14
5.2.80.0000.06711.01
5.2.70.0030.05311.02
5.2.60.0000.06011.04
5.2.50.0070.05711.00
5.2.40.0070.05310.92
5.2.30.0030.05010.80
5.2.20.0100.05010.93
5.2.10.0070.02710.88
5.2.00.0000.03010.77
5.1.60.0030.02010.01
5.1.50.0000.0239.98
5.1.40.0000.0239.85
5.1.30.0070.02310.33
5.1.20.0000.02710.33
5.1.10.0000.02310.02
5.1.00.0000.02710.04
5.0.50.0000.0209.02
5.0.40.0000.0179.02
5.0.30.0000.0279.02
5.0.20.0000.0209.02
5.0.10.0000.0179.02
5.0.00.0000.0239.02
4.4.90.0000.0309.02
4.4.80.0000.0339.02
4.4.70.0000.0339.02
4.4.60.0000.0209.02
4.4.50.0000.0309.02
4.4.40.0000.0239.02
4.4.30.0030.0139.02
4.4.20.0030.0109.02
4.4.10.0030.0139.02
4.4.00.0000.0239.02
4.3.110.0000.0139.02
4.3.100.0000.0179.02
4.3.90.0000.0139.02
4.3.80.0000.0239.02
4.3.70.0000.0209.02
4.3.60.0000.0179.02
4.3.50.0070.0179.02
4.3.40.0030.0179.02
4.3.30.0000.0139.02
4.3.20.0000.0139.02
4.3.10.0000.0179.02
4.3.00.0000.0139.02

preferences:
39.2 ms | 401 KiB | 5 Q