3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface ProductRepository { public function findReferenceBySku(string $sku): Product; public function findIdBySku(string $sku): int; } class Product { public function __construct( public int $id, ) { } } class ProductDatabaseRepository implements ProductRepository { public function findReferenceBySku(string $sku): Product { $id = $this->findIdBySku($sku); return $this->getProductReference($id); } private function getProductReference(int $id) { // check entity manager for existing object // and generate proxy if not found return new Product($id); } public function findIdBySku(string $sku): int { $this->queryDatabase(); return match($sku) { 'sku1' => 1, }; } protected function queryDatabase() { // note this method is not public var_dump('query database'); } } class ProductCachedRepository implements ProductRepository { private array $cachedIds = []; public function __construct( private ProductRepository $inner ) {} public function findReferenceBySku(string $sku): Product { // not able to delegate this logic directly to inner class // (loss of findIdBySku() overridden logic) //return $this->inner->findReferenceBySku($sku); // as well not able call decorated method with substitude this return $this->inner->findReferenceBySku(...)->call($this, $sku); } public function findIdBySku(string $sku): int { var_dump('check cache'); return $this->cachedIds[$sku] ??= $this->inner->findIdBySku($sku); } public function __call($name, $arguments) { // all not public methods of inner repository // which are not declared in current class // are delegated to inner repository return (fn() => $this->$name(...$arguments)) ->call($this->inner); } } $repository = (new ProductCachedRepository(new ProductDatabaseRepository())); var_dump('call1', $repository->findReferenceBySku('sku1')); var_dump('call2', $repository->findReferenceBySku('sku1')); // cache hit expected var_dump('call2', $repository->findReferenceBySku('sku1')); // cache hit expected

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.4.120.0080.00924.07
8.4.110.0060.00819.83
8.4.100.0120.00918.47
8.4.90.0150.00418.79
8.4.80.0130.00819.48
8.4.70.0090.01118.24
8.4.60.0150.00818.77
8.4.50.0100.00820.54
8.4.40.0160.00318.02
8.4.30.0030.01220.48
8.4.20.0130.00717.78
8.4.10.0070.01318.03
8.3.250.0120.00718.84
8.3.240.0110.00817.25
8.3.230.0120.00717.05
8.3.220.0110.00817.16
8.3.210.0100.00916.72
8.3.200.0050.00316.82
8.3.190.0100.00917.36
8.3.180.0120.00619.11
8.3.170.0150.00317.38
8.3.160.0040.01420.94
8.3.150.0060.01217.11
8.3.140.0070.00319.01
8.3.130.0090.00018.63
8.3.120.0060.00320.78
8.3.110.0150.00422.58
8.3.100.0000.00920.94
8.3.90.0040.00420.94
8.3.50.0060.00320.94
8.2.290.0110.00920.67
8.2.280.0060.00218.54
8.2.270.0150.00420.67
8.2.260.0070.01116.77
8.2.250.0090.00916.91
8.2.240.0040.00417.13
8.2.230.0070.00422.58
8.2.220.0030.00722.58
8.2.210.0040.00422.58
8.1.330.0130.00721.73
8.1.320.0090.00516.00
8.1.310.0100.00716.42
8.1.300.0100.01017.81
8.1.20.0040.00417.67
8.1.10.0050.00217.56
8.1.00.0000.00817.55
8.0.150.0000.00716.83
8.0.140.0000.00716.68
8.0.130.0000.00716.88
8.0.120.0040.00416.79
8.0.110.0040.00416.86
8.0.100.0070.00016.75
8.0.90.0040.00416.83
8.0.80.0000.00816.79
8.0.70.0000.00716.84
8.0.60.0000.00716.70
8.0.50.0070.00016.79
8.0.30.0000.00716.86
8.0.20.0040.00416.92
8.0.10.0040.00416.92
7.4.270.0030.00316.32
7.4.260.0000.00816.41
7.4.250.0030.00316.26
7.4.240.0040.00416.47
7.4.230.0040.00416.30
7.4.220.0000.00816.32
7.4.210.0040.00416.25
7.4.200.0030.00316.41
7.4.190.0030.00316.29
7.4.180.0070.00016.31
7.4.160.0030.00316.30
7.4.150.0030.00316.23
7.4.140.0030.00516.13
7.4.130.0000.00716.21
7.4.120.0030.00316.16
7.4.110.0000.00716.12
7.4.100.0000.00716.32
7.4.90.0030.00316.20
7.4.80.0030.00316.33
7.4.70.0000.00716.10
7.4.60.0030.00316.27
7.4.50.0070.00016.14
7.4.40.0030.00316.02
7.4.30.0000.00716.07
7.4.20.0040.00416.21
7.4.10.0070.00016.21
7.4.00.0000.00716.20

preferences:
26.98 ms | 403 KiB | 5 Q