3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $a; protected $b; public $c; } class FooCountable implements \Countable { private $elements = [1,2,3]; public function count() { return count($this->elements); } } $tests = [ 'array' => [1,2,3], 'string' => 'hello world', 'number' => 123, 'iterator' => new \ArrayIterator([1,2,3]), 'countable' => new \FooCountable(), 'zero' => 0, 'string_zero' => '0', 'object' => new \Foo(), 'stdClass' => new \stdClass, 'null' => null, 'empty' => '', 'boolt' => true, 'boolf' => false ]; function ignoreCount($data) { return @count($data); } function validatedCount($data) { if (PHP_VERSION_ID >= 70300) { if (is_countable($data)) { return count($data); } } elseif (PHP_VERSION_ID >= 70100) { if (is_array($data) || $data instanceof \Countable) { return count($data); } elseif(is_iterable($data)) { return iterator_count($data); } } else { if (is_array($data) || $data instanceof \Countable) { return count($data); } elseif ($data instanceof \Traversable) { return iterator_count($data); } } return null === $data ? 0 : 1; } function castCount($data) { return count((array) $data); } foreach ($tests as $type => $data) { $expected = @count($data); $normal = count($data); $ignored = ignoreCount($data); $validated = validatedCount($data); $casted = castCount($data); echo 'Type ' . $type . ': ' . \PHP_EOL; echo "\t" . 'count(): ' . print_r($normal, 1) . ' '; var_dump($normal === $expected); echo "\t" . 'Ignored: ' . print_r($ignored, 1) . ' '; var_dump($ignored === $expected); echo "\t" . 'Validated: ' . print_r($validated, 1) . ' '; var_dump($validated === $expected); echo "\t" . 'Casted: ' . print_r($casted, 1) . ' '; var_dump($casted === $expected); echo \PHP_EOL . '------' . \PHP_EOL . \PHP_EOL; }

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.110.0030.00520.94
8.3.100.0030.00624.06
8.3.90.0080.00326.77
8.3.80.0000.00917.97
8.3.70.0130.00316.88
8.3.60.0110.00718.55
8.3.50.0090.00418.49
8.3.40.0070.00718.84
8.3.30.0090.00618.76
8.3.20.0080.00018.73
8.3.10.0040.00423.70
8.3.00.0070.00021.96
8.2.230.0030.00722.58
8.2.220.0130.00737.54
8.2.210.0080.00826.77
8.2.200.0100.00016.88
8.2.190.0100.00616.89
8.2.180.0160.00316.75
8.2.170.0090.00622.96
8.2.160.0070.00719.46
8.2.150.0070.00425.66
8.2.140.0030.00724.66
8.2.130.0040.00426.16
8.2.120.0040.00420.84
8.2.110.0130.00620.96
8.2.100.0080.00417.95
8.2.90.0000.00919.21
8.2.80.0060.00317.97
8.2.70.0030.00518.04
8.2.60.0040.00418.09
8.2.50.0040.00418.10
8.2.40.0080.00019.46
8.2.30.0040.00420.59
8.2.20.0040.00418.25
8.2.10.0090.00019.84
8.2.00.0040.00419.48
8.1.290.0030.00630.84
8.1.280.0040.01125.92
8.1.270.0040.00420.64
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0040.00717.78
8.1.230.0110.00018.95
8.1.220.0000.00817.79
8.1.210.0040.00418.77
8.1.200.0080.00017.35
8.1.190.0050.00317.35
8.1.180.0030.00618.10
8.1.170.0080.00018.70
8.1.160.0040.00418.86
8.1.150.0070.00018.86
8.1.140.0040.00420.67
8.1.130.0000.00721.95
8.1.120.0000.00717.41
8.1.110.0070.00017.53
8.1.100.0070.00417.42
8.1.90.0000.00717.52
8.1.80.0000.00817.55
8.1.70.0080.00017.50
8.1.60.0000.00917.64
8.1.50.0060.00317.58
8.1.40.0040.00417.44
8.1.30.0030.00617.65
8.1.20.0000.00717.73
8.1.10.0030.00617.53
8.1.00.0030.00517.59
8.0.300.0000.00718.77
8.0.290.0030.00516.88
8.0.280.0000.00718.51
8.0.270.0030.00517.23
8.0.260.0000.00720.17
8.0.250.0030.00317.09
8.0.240.0040.00417.01
8.0.230.0050.00317.08
8.0.220.0000.00716.98
8.0.210.0040.00416.91
8.0.200.0030.00317.08
8.0.190.0000.00716.96
8.0.180.0030.00517.05
8.0.170.0060.00317.04
8.0.160.0000.00916.99
8.0.150.0040.00416.84
8.0.140.0030.00516.85
8.0.130.0050.00013.38
8.0.120.0000.00716.89
8.0.110.0040.00416.84
8.0.100.0000.00816.99
8.0.90.0000.00716.89
8.0.80.0060.01016.93
8.0.70.0000.00716.93
8.0.60.0000.00716.97
8.0.50.0030.00516.88
8.0.30.0090.00917.21
8.0.20.0120.01117.40
8.0.10.0000.00717.05
8.0.00.0090.00916.64
7.4.330.0020.00215.55
7.4.320.0000.00916.53
7.4.300.0070.00016.59
7.4.290.0030.00316.60
7.4.280.0040.00416.61
7.4.270.0000.01016.52
7.4.260.0000.00716.62
7.4.250.0050.00216.48
7.4.240.0070.00016.61
7.4.230.0040.00416.44
7.4.220.0040.00416.66
7.4.210.0100.00816.51
7.4.200.0050.00216.43
7.4.160.0060.01116.60
7.4.140.0110.01117.86
7.4.130.0070.01716.55
7.4.120.0080.01216.56
7.4.110.0140.00316.60
7.4.100.0130.01016.40
7.4.90.0070.01016.65
7.4.80.0140.00519.39
7.4.70.0190.00416.68
7.4.60.0100.01016.42
7.4.50.0090.00616.31
7.4.40.0070.01016.46
7.4.00.0030.01315.12
7.3.330.0000.00513.29
7.3.320.0050.00313.29
7.3.310.0000.00816.52
7.3.300.0040.00416.29
7.3.290.0000.00716.50
7.3.280.0090.00916.44
7.3.260.0090.01016.43
7.3.240.0070.01316.58
7.3.230.0130.00816.63
7.3.210.0100.00716.50
7.3.200.0110.00516.39
7.3.190.0070.01716.46
7.3.180.0130.01016.32
7.3.170.0120.01216.59
7.3.160.0060.01316.47
7.2.330.0030.02016.55
7.2.320.0120.00816.91
7.2.310.0190.00416.84
7.2.300.0150.00316.84
7.2.290.0180.00016.53
7.2.110.0200.00316.79
7.2.90.0110.00714.57
7.2.80.3960.00315.00
7.2.70.3760.01315.36
7.2.60.3950.01015.08
7.2.50.4260.01315.04
7.2.40.4010.01014.75
7.2.30.5180.00014.94
7.2.20.2760.00615.15
7.2.10.4030.00715.09
7.2.00.3280.00614.77
7.1.210.4320.00613.68
7.1.200.1150.01314.10
7.1.190.2920.00614.14
7.1.180.3760.00314.04
7.1.170.4800.00713.86
7.1.160.4950.01013.73
7.1.150.5740.00713.76
7.1.140.2020.01013.91
7.1.130.2390.00014.01
7.1.120.2910.00613.37
7.1.110.4990.00313.46
7.1.100.4480.01313.80
7.1.90.5390.01313.74
7.1.80.5840.00313.67
7.1.70.4930.00613.84
7.1.60.5830.01332.07
7.1.50.5820.02031.75
7.1.40.6760.00731.33
7.1.30.4060.00631.38
7.1.20.5430.01632.00
7.1.10.5320.00013.84
7.1.00.4010.00013.86

preferences:
28.13 ms | 403 KiB | 5 Q