3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ArrayAnalyzer { /** * The rules to test. * * @var array */ protected $rules; public function __construct(ArrayAnalyzerRule ...$rules) { $this->rules = $rules; } /** * Analyzes an array with each of the rules, and returns the report. * * @param array $array * @return array */ public function analyze(array $array) { $report = []; foreach ($this->rules as $key => $rule) { if ($rule->fulfilledBy($array)) { $report[$key] = $rule->getValue($array); } } return $report; } } interface ArrayAnalyzerRule { /** * Checks whether the rule is fulfilled by the passed array. * * @param array $array * @return boolean */ public function fulfilledBy(array $array); /** * Gets the rule output value. * * @param array $array * @return array */ public function getValue(array $array); } class AllIntegersRule implements ArrayAnalyzerRule { /** * {@inheritDoc} */ public function fulfilledBy(array $array) { return array_reduce($array, function ($carry, $item) { return $carry && is_int($item); }, true); } /** * {@inheritDoc} */ public function getValue(array $array) { return true; } } class SameLengthRule implements ArrayAnalyzerRule { public function fulfilledBy(array $array) { return count(array_unique(array_map(function ($item) { return mb_strlen($item); }, $array))) === 1; } /** * {@inheritDoc} */ public function getValue(array $array) { return mb_strlen($array[0]); } } $arrayAnalyzer = new ArrayAnalyzer([ 'isInteger' => new AllIntegersRule, 'length' => new SameLengthRule, ]); var_dump($arrayAnalyzer->analyze([1, 2, 3])); var_dump($arrayAnalyzer->analyze([1, 2, 'D'])); var_dump($arrayAnalyzer->analyze([1, 2, '3D']));

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)
8.3.60.0040.01116.88
8.3.50.0140.00921.09
8.3.40.0110.01118.76
8.3.30.0080.00618.68
8.3.20.0040.00420.30
8.3.10.0030.00621.91
8.3.00.0000.00822.46
8.2.180.0110.01116.88
8.2.170.0130.00322.96
8.2.160.0000.01422.25
8.2.150.0000.00725.66
8.2.140.0090.00024.66
8.2.130.0030.00526.16
8.2.120.0030.00617.63
8.2.110.0030.00621.03
8.2.100.0060.00617.75
8.2.90.0030.00619.17
8.2.80.0000.00817.97
8.2.70.0050.00317.75
8.2.60.0000.00918.03
8.2.50.0030.00618.07
8.2.40.0050.00321.16
8.2.30.0040.00419.76
8.2.20.0050.00317.85
8.2.10.0000.00818.21
8.2.00.0000.00718.11
8.1.280.0070.01025.92
8.1.270.0080.00020.33
8.1.260.0050.00326.35
8.1.250.0050.00228.09
8.1.240.0090.00022.69
8.1.230.0110.00017.48
8.1.220.0040.00417.74
8.1.210.0080.00018.77
8.1.200.0060.00317.23
8.1.190.0050.00317.38
8.1.180.0000.00818.10
8.1.170.0030.00518.61
8.1.160.0040.00422.05
8.1.150.0030.00618.98
8.1.140.0040.00417.60
8.1.130.0000.00817.70
8.1.120.0040.00417.52
8.1.110.0000.00817.41
8.1.100.0000.00817.50
8.1.90.0040.00417.39
8.1.80.0050.00217.54
8.1.70.0040.00417.45
8.1.60.0040.00417.56
8.1.50.0050.00317.53
8.1.40.0080.00017.56
8.1.30.0050.00317.51
8.1.20.0040.00417.59
8.1.10.0050.00517.47
8.1.00.0030.00617.37
8.0.300.0040.00418.77
8.0.290.0000.00816.88
8.0.280.0030.00318.55
8.0.270.0070.00017.24
8.0.260.0000.00617.33
8.0.250.0040.00417.04
8.0.240.0030.00617.09
8.0.230.0070.00316.93
8.0.220.0030.00316.96
8.0.210.0000.00716.99
8.0.200.0070.00017.06
8.0.190.0080.00417.07
8.0.180.0000.00817.02
8.0.170.0000.00817.08
8.0.160.0000.00716.99
8.0.150.0070.00016.81
8.0.140.0000.00716.94
8.0.130.0000.00613.35
8.0.120.0000.00816.99
8.0.110.0050.00316.96
8.0.100.0070.00016.96
8.0.90.0070.00016.86
8.0.80.0090.00616.95
8.0.70.0050.00316.94
8.0.60.0040.00417.00
8.0.50.0040.00416.96
8.0.30.0140.00617.21
8.0.20.0060.01217.40
8.0.10.0000.00717.01
8.0.00.0120.00916.70
7.4.330.0050.00015.08
7.4.320.0070.00016.54
7.4.300.0060.00016.60
7.4.290.0000.00716.65
7.4.280.0060.00316.62
7.4.270.0040.00416.66
7.4.260.0070.00016.51
7.4.250.0000.00816.48
7.4.240.0060.00216.61
7.4.230.0000.00816.45
7.4.220.0030.01616.67
7.4.210.0120.01016.41
7.4.200.0070.00016.63
7.4.160.0070.01116.43
7.4.150.0120.00617.40
7.4.140.0120.01117.86
7.4.130.0190.00316.63
7.4.120.0110.00916.49
7.4.110.0140.00316.57
7.4.100.0030.01716.60
7.4.90.0060.01116.54
7.4.80.0120.00919.39
7.4.70.0170.00516.37
7.4.60.0090.00916.71
7.4.50.0060.00316.51
7.4.40.0100.00616.60
7.4.30.0060.01516.66
7.4.00.0120.00715.05
7.3.330.0060.00313.24
7.3.320.0030.00513.41
7.3.310.0030.00316.28
7.3.300.0040.00416.39
7.3.290.0040.01216.44
7.3.280.0100.00916.41
7.3.270.0110.00617.40
7.3.260.0170.00716.68
7.3.250.0060.01316.52
7.3.240.0140.00416.39
7.3.230.0110.00516.56
7.3.210.0140.00316.32
7.3.200.0150.00619.39
7.3.190.0060.00916.56
7.3.180.0060.00916.47
7.3.170.0090.00916.55
7.3.160.0070.01116.67
7.3.120.0040.01514.79
7.3.110.0110.00714.74
7.3.100.0080.00414.97
7.3.90.0090.00614.80
7.3.80.0120.00314.94
7.3.70.0070.00714.84
7.3.60.0000.01014.62
7.3.50.0090.00914.82
7.3.40.0060.00614.95
7.3.30.0040.00414.95
7.3.20.0110.00416.47
7.3.10.0110.00316.85
7.3.00.0050.00516.68
7.2.330.0120.00616.66
7.2.320.0110.01016.71
7.2.310.0080.00816.48
7.2.300.0030.01316.60
7.2.290.0070.01016.36
7.2.250.0030.01614.65
7.2.240.0110.00715.05
7.2.230.0070.00714.95
7.2.220.0080.00614.87
7.2.210.0030.00814.90
7.2.200.0090.00615.02
7.2.190.0060.01015.13
7.2.180.0060.01214.98
7.2.170.0100.00314.82
7.2.60.0070.00416.30
7.2.00.0040.00819.39
7.1.330.0090.00015.75
7.1.320.0040.00415.64
7.1.310.0110.00715.55
7.1.300.0090.00615.71
7.1.290.0000.01115.72
7.1.280.0000.00815.59
7.1.270.0030.01315.75
7.1.260.0040.00715.73
7.1.200.0240.00315.56
7.1.100.0000.01217.80
7.1.70.0000.00717.14
7.1.60.0100.01319.18
7.1.50.0190.01916.97
7.1.00.0030.07722.37
7.0.200.0040.01114.80
7.0.60.0070.08719.97
7.0.50.0030.04717.89
7.0.40.0200.07320.52
7.0.30.0500.06320.30
7.0.20.0200.04720.06
7.0.10.0130.07320.15
7.0.00.0030.06020.05
5.6.280.0000.06720.95
5.6.210.0100.07720.49
5.6.200.0000.08718.15
5.6.190.0070.05720.33
5.6.180.4100.04320.58
5.6.170.0200.08720.51
5.6.160.0070.05020.47
5.6.150.0100.08018.17
5.6.140.0030.03718.28
5.6.130.0100.07318.21
5.6.120.0130.08020.99
5.6.110.0070.09021.00
5.6.100.0070.08321.00
5.6.90.0130.07721.12
5.6.80.0030.04020.39
5.6.70.4430.03720.55
5.5.350.0200.04720.40
5.5.340.0100.03717.98
5.5.330.0070.07720.21
5.5.320.3970.04020.35
5.5.310.0270.05320.19
5.5.300.0070.05318.03
5.5.290.0000.06017.92
5.5.280.0130.03720.96
5.5.270.0030.08320.78
5.5.260.0070.03720.68
5.5.250.0030.06020.46
5.5.240.0200.07720.16
5.4.450.0900.05719.59
5.4.440.0770.05319.58
5.4.430.1000.05719.57
5.4.420.1070.06019.48
5.4.410.1070.06319.35
5.4.400.0870.06719.16
5.4.390.1070.06019.29
5.4.380.0970.05719.16
5.4.370.0800.05719.04
5.4.360.0970.05019.26
5.4.350.0800.05019.25
5.4.340.0730.06019.27
5.4.320.0800.05319.28
5.4.310.0600.07718.87
5.4.300.0200.04319.26
5.4.290.0130.05019.26
5.4.280.0500.05719.14
5.4.270.0730.05718.83
5.4.260.0700.06719.12
5.4.250.0630.06019.27
5.4.240.0830.04319.21
5.4.230.0870.05319.27
5.4.220.0800.04718.88
5.4.210.0830.06019.03
5.4.200.0700.05716.95
5.4.190.0800.05319.14
5.4.180.0730.05319.03
5.4.170.0970.05318.88
5.4.160.0800.05319.02
5.4.150.0830.05719.09
5.4.140.0800.06316.36
5.4.130.0770.04716.54
5.4.120.0730.05316.45
5.4.110.0800.04016.45
5.4.100.0830.05316.55
5.4.90.0770.05016.43
5.4.80.0730.05316.71
5.4.70.0730.06016.70
5.4.60.0370.06316.43
5.4.50.0000.07716.38
5.4.40.0170.03316.51
5.4.30.0300.06716.38
5.4.20.0330.05016.43

preferences:
43.02 ms | 401 KiB | 5 Q