3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); final class Immutable { private $data; private $mutable = true; public function __construct(array $args) { if (false === $this->mutable) { throw new \BadMethodCallException('Constructor called twice.'); } $this->data = $this->sanitiseInput($args); $this->mutable = false; } public function getData(): array { return $this->data; } public function sanitiseInput(array $args): array { return array_map(function($x) { if (is_scalar($x)) return $x; else if (is_object($x)) return $this->sanitiseObject($x); else if (is_array($x)) return $this->sanitiseInput($x); else throw new \InvalidArgumentException('Resources cannot be made immutable.'); }, $args); } private static function sanitiseObject(Immutable $object): Immutable { return clone $object; } public function __clone() { $this->data = $this->sanitiseInput($this->data); } public function __unset(string $id): void {} public function __set(string $id, $val): void {} } $a = new Immutable([new stdClass, 10, 'yayaya']); $b = new Immutable([1]); var_dump($a); var_dump($b);

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.0180.00316.63
8.3.50.0110.00716.61
8.3.40.0040.01518.83
8.3.30.0120.00618.79
8.3.20.0000.01420.25
8.3.10.0040.00421.66
8.3.00.0030.00517.93
8.2.180.0130.00716.88
8.2.170.0090.00922.96
8.2.160.0120.00321.07
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0000.00820.25
8.2.120.0030.00726.35
8.2.110.0040.00421.00
8.2.100.0040.00717.84
8.2.90.0000.00819.34
8.2.80.0040.00417.97
8.2.70.0000.00817.63
8.2.60.0000.00817.50
8.2.50.0040.00418.04
8.2.40.0000.00822.38
8.2.30.0070.00019.38
8.2.20.0040.00418.12
8.2.10.0120.00018.36
8.2.00.0040.00418.35
8.1.280.0070.01425.92
8.1.270.0040.00423.92
8.1.260.0050.00326.35
8.1.250.0030.00528.09
8.1.240.0080.00322.42
8.1.230.0000.01120.90
8.1.220.0050.00317.74
8.1.210.0030.00618.88
8.1.200.0100.00017.60
8.1.190.0030.00617.35
8.1.180.0030.00618.10
8.1.170.0030.00518.51
8.1.160.0050.00318.93
8.1.150.0040.00420.11
8.1.140.0000.00719.57
8.1.130.0000.00719.05
8.1.120.0040.00417.43
8.1.110.0000.00817.38
8.1.100.0000.00817.49
8.1.90.0000.00717.41
8.1.80.0080.00017.51
8.1.70.0030.00317.35
8.1.60.0060.00317.57
8.1.50.0050.00217.45
8.1.40.0040.00417.55
8.1.30.0000.00817.53
8.1.20.0050.00317.66
8.1.10.0040.00417.46
8.1.00.0040.00417.39
8.0.300.0050.00320.01
8.0.290.0060.00317.00
8.0.280.0000.00818.50
8.0.270.0000.00717.30
8.0.260.0030.00319.01
8.0.250.0000.00617.08
8.0.240.0050.00317.07
8.0.230.0000.00717.02
8.0.220.0000.00717.01
8.0.210.0030.00317.00
8.0.200.0080.00017.06
8.0.190.0000.00817.06
8.0.180.0000.00717.04
8.0.170.0040.00417.02
8.0.160.0000.00917.05
8.0.150.0000.00816.95
8.0.140.0090.00016.95
8.0.130.0000.00513.50
8.0.120.0070.00017.00
8.0.110.0040.00416.88
8.0.100.0000.00816.86
8.0.90.0040.00417.08
8.0.80.0090.00616.93
8.0.70.0040.00417.03
8.0.60.0000.00716.89
8.0.50.0000.00716.89
8.0.30.0100.00717.22
8.0.20.0110.00917.40
8.0.10.0030.00516.95
8.0.00.0130.01016.96
7.4.330.0030.00515.55
7.4.320.0070.00016.40
7.4.300.0030.00316.50
7.4.290.0000.00716.49
7.4.280.0080.00016.50
7.4.270.0060.00316.60
7.4.260.0000.00716.49
7.4.250.0070.00016.37
7.4.240.0030.00316.52
7.4.230.0000.00716.48
7.4.220.0090.00916.57
7.4.210.0040.01216.48
7.4.200.0030.00316.45
7.4.160.0110.00516.49
7.4.150.0060.01317.40
7.4.140.0140.00817.86
7.4.130.0070.01216.55
7.4.120.0080.01416.54
7.4.110.0060.01116.54
7.4.100.0140.00716.59
7.4.90.0130.00316.62
7.4.80.0060.01219.39
7.4.70.0040.01716.48
7.4.60.0160.00316.48
7.4.50.0030.01316.31
7.4.40.0100.01316.54
7.4.30.0000.01716.63
7.4.00.0110.00715.09
7.3.330.0030.00313.43
7.3.320.0000.00613.43
7.3.310.0000.00716.44
7.3.300.0040.00416.46
7.3.290.0070.00016.37
7.3.280.0110.00716.38
7.3.270.0060.01317.40
7.3.260.0090.00916.55
7.3.250.0070.01316.41
7.3.240.0090.00916.48
7.3.230.0140.00716.39
7.3.210.0100.00716.43
7.3.200.0060.00916.57
7.3.190.0160.00016.51
7.3.180.0100.00616.41
7.3.170.0130.00316.50
7.3.160.0120.00616.46
7.3.120.0100.00814.79
7.3.110.0070.01014.76
7.3.100.0030.01014.81
7.3.90.0050.01114.73
7.3.80.0090.00514.97
7.3.70.0120.00714.65
7.3.60.0050.01014.84
7.3.50.0020.01114.75
7.3.40.0100.00514.77
7.3.30.0080.00914.82
7.3.20.0040.00616.65
7.3.10.0070.00616.68
7.3.00.0070.00716.58
7.2.330.0060.01216.61
7.2.320.0110.00716.84
7.2.310.0040.01216.60
7.2.300.0120.01016.76
7.2.290.0060.01216.74
7.2.250.0100.00815.16
7.2.240.0050.01215.30
7.2.230.0070.01015.07
7.2.220.0060.01014.95
7.2.210.0050.00915.15
7.2.200.0080.00715.22
7.2.190.0030.00815.02
7.2.180.0010.00815.05
7.2.170.0050.01115.16
7.2.130.0040.00416.89
7.2.120.0030.01116.78
7.2.110.0030.01317.01
7.2.100.0000.01416.90
7.2.90.0070.00717.16
7.2.80.0060.01016.96
7.2.70.0110.00716.96
7.2.60.0080.00817.01
7.2.50.0040.01116.77
7.2.40.0000.01517.09
7.2.30.0000.01317.10
7.2.20.0000.01417.06
7.2.10.0070.00316.99
7.2.00.0070.00818.08
7.1.330.0030.01215.85
7.1.320.0110.00315.69
7.1.310.0090.00515.79
7.1.300.0030.00815.62
7.1.290.0070.01015.66
7.1.280.0110.00715.63
7.1.270.0040.01015.72
7.1.260.0050.00615.71
7.1.250.0030.00815.77
7.1.200.0050.00815.64
7.1.70.0030.00617.26
7.1.60.0000.01116.93
7.1.50.0040.01416.97
7.1.40.0470.01032.50
7.1.30.0500.00732.49
7.1.20.0670.01332.49
7.1.10.0270.01314.51
7.1.00.0330.01014.78
7.0.200.0030.01216.78
7.0.180.0870.01014.23
7.0.170.0500.01014.42
7.0.160.0470.01314.21
7.0.150.0400.00314.22
7.0.140.0430.01014.36
7.0.130.0330.00314.66
7.0.120.0270.01014.56
7.0.110.0330.00714.66
7.0.100.0300.01314.48
7.0.90.0230.01314.62
7.0.80.0300.00714.71
7.0.70.0300.01014.52
7.0.60.0300.00714.33
7.0.50.0270.00714.45
7.0.40.0270.01014.78
7.0.30.0270.00714.61
7.0.20.0270.01014.58
7.0.10.0300.00314.47
7.0.00.0230.01014.36

preferences:
48.87 ms | 401 KiB | 5 Q