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; }); } $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)
7.4.00.0180.05525.25
7.3.120.0200.05725.30
7.3.110.0120.07925.02
7.3.100.0120.04625.09
7.3.90.0130.04725.29
7.3.80.0130.04725.08
7.3.70.0120.04525.28
7.3.60.0180.04125.21
7.3.50.0030.05525.41
7.3.40.0050.04925.17
7.3.30.0130.04824.27
7.3.20.0080.04527.20
7.3.10.0070.04627.01
7.3.00.0100.04026.98
7.2.250.0130.06924.53
7.2.240.0120.06124.34
7.2.230.0080.05824.45
7.2.220.0200.05324.23
7.2.210.0100.05424.54
7.2.200.0140.04824.41
7.2.190.0070.05524.41
7.2.180.0100.05624.41
7.2.170.0030.05824.46
7.2.130.0130.04227.38
7.2.120.0000.05826.95
7.2.110.0070.05326.95
7.2.100.0100.04826.94
7.2.90.0070.05027.16
7.2.80.0030.05227.14
7.2.70.0030.05126.99
7.2.60.0000.05826.94
7.2.50.0130.04826.95
7.2.40.0130.04827.32
7.2.30.0060.04527.21
7.2.20.0070.04827.25
7.2.10.0160.04827.17
7.2.00.0100.05328.38
7.1.330.0070.08726.15
7.1.320.0080.08225.81
7.1.310.0100.08726.01
7.1.300.0080.08826.02
7.1.290.0050.09326.15
7.1.280.0070.07826.07
7.1.270.0120.07826.01
7.1.260.0080.08726.11
7.1.250.0060.07726.09
7.1.70.0030.05527.56
7.1.60.0160.08527.74
7.1.50.0070.04727.49
7.1.00.0000.14332.72
7.0.200.0060.05527.20
7.0.140.0030.13732.49
7.0.60.0100.10729.19
7.0.50.0170.14027.29
7.0.40.0200.13023.90
7.0.30.0330.13023.83
7.0.20.0400.13723.92
7.0.10.0070.10323.93
7.0.00.0200.10023.91
5.6.280.0200.22763.99
5.6.210.0330.20063.08
5.6.200.0200.20060.61
5.6.190.0200.15762.85
5.6.180.0570.15062.85
5.6.170.0330.20362.86
5.6.160.0170.21062.80
5.6.150.0270.14760.46
5.6.140.0100.16060.62
5.6.130.0170.17360.63
5.6.120.0130.16063.52
5.6.110.0400.21063.45
5.6.100.0230.23063.50
5.6.90.0070.19063.49
5.6.80.0170.23762.85
5.5.350.0570.19362.89
5.5.340.0130.21360.41
5.5.330.0170.21062.63
5.5.320.0170.18364.50
5.5.310.0470.16062.57
5.5.300.0200.22060.39
5.5.290.0130.17360.51
5.5.280.0370.21363.36
5.5.270.0130.24763.23
5.5.260.0370.18763.31
5.5.250.0230.20763.15
5.5.240.0200.22062.78
5.4.450.1470.22361.58
5.4.440.0800.26361.85
5.4.430.0830.26362.03
5.4.420.1200.23361.96
5.4.410.1130.22761.88
5.4.400.0700.26361.23
5.4.390.0570.27361.01
5.4.380.0430.28361.90
5.4.370.0200.30061.13
5.4.360.0400.18060.96
5.4.350.0310.23954.48
5.4.340.0360.28554.46
5.4.320.0190.20154.98
5.4.310.0210.17554.97
5.4.300.0210.17954.98
5.4.290.0190.18654.97
5.4.280.0120.18654.87
5.4.270.0190.18154.87
5.4.260.0210.18454.87
5.4.250.0150.18654.87
5.4.240.0150.18654.87
5.4.230.0170.18654.86
5.4.220.0150.18354.86
5.4.210.0160.18554.86
5.4.200.0190.17754.86
5.4.190.0190.17654.86
5.4.180.0210.18754.86
5.4.170.0170.19654.86
5.4.160.0180.18254.86
5.4.150.0200.17754.86
5.4.140.0220.18154.54
5.4.130.0230.17554.53
5.4.120.0200.17954.48
5.4.110.0200.18054.48
5.4.100.0230.17454.48
5.4.90.0270.23854.48
5.4.80.0200.20054.48
5.4.70.0170.19554.48
5.4.60.0220.22154.48
5.4.50.0190.19254.48
5.4.40.0200.18954.47
5.4.30.0250.18554.46
5.4.20.0230.19954.46
5.4.10.0230.18054.46
5.4.00.0200.17553.95
5.3.290.0280.19974.59
5.3.280.0280.17174.52
5.3.270.0350.17174.53
5.3.260.0310.16774.53
5.3.250.0290.16674.54
5.3.240.0280.16374.53
5.3.230.0260.17875.33
5.3.220.0300.17374.50
5.3.210.0300.20374.49
5.3.200.0260.16974.49
5.3.190.0250.17474.49
5.3.180.0290.17674.49
5.3.170.0270.17574.48
5.3.160.0280.17874.48
5.3.150.0300.16974.49
5.3.140.0310.18574.48
5.3.130.0320.19575.01
5.3.120.0240.17974.47
5.3.110.0310.18074.47
5.3.100.0210.19073.96
5.3.90.0310.16673.95
5.3.80.0250.17373.93
5.3.70.0320.17473.93
5.3.60.0210.18873.92
5.3.50.0280.18573.87
5.3.40.0320.17973.87
5.3.30.0270.16473.83
5.3.20.0300.16973.61
5.3.10.0180.18673.57
5.3.00.0230.17573.55
5.2.170.0050.0319.24
5.2.160.0040.0309.24
5.2.150.0040.0319.24
5.2.140.0070.0299.23
5.2.130.0070.0269.20
5.2.120.0010.0329.20
5.2.110.0060.0299.20
5.2.100.0070.0279.19
5.2.90.0040.0319.20
5.2.80.0050.0339.19
5.2.70.0070.0409.19
5.2.60.0070.0289.15
5.2.50.0060.0339.12
5.2.40.0070.0399.09
5.2.30.0050.0329.07
5.2.20.0090.0269.05
5.2.10.0050.0278.96
5.2.00.0020.0318.83
5.1.60.0060.0238.11
5.1.50.0040.0258.11
5.1.40.0050.0248.09
5.1.30.0020.0288.43
5.1.20.0030.0288.46
5.1.10.0040.0278.18
5.1.00.0050.0258.19
5.0.50.0040.0286.66
5.0.40.0050.0186.52
5.0.30.0030.0326.33
5.0.20.0090.0136.30
5.0.10.0030.0246.27
5.0.00.0030.0316.27
4.4.90.0030.0154.78
4.4.80.0020.0194.75
4.4.70.0040.0164.76
4.4.60.0030.0254.76
4.4.50.0020.0234.77
4.4.40.0040.0284.71
4.4.30.0040.0144.76
4.4.20.0030.0234.85
4.4.10.0030.0174.85
4.4.00.0030.0244.76
4.3.110.0040.0174.67
4.3.100.0030.0144.66
4.3.90.0060.0174.63
4.3.80.0010.0304.59
4.3.70.0050.0164.63
4.3.60.0020.0154.63
4.3.50.0020.0164.63
4.3.40.0060.0254.54
4.3.30.0020.0163.30
4.3.20.0040.0243.28
4.3.10.0030.0153.24
4.3.00.0130.0237.15

preferences:
39.53 ms | 400 KiB | 5 Q