3v4l.org

run code in 300+ PHP versions simultaneously
<?php /********************** OBJECTS **********************/ interface OldInterface {} class OldA implements OldInterface {} class OldB implements OldInterface {} interface NewInterface {} class NewA implements NewInterface {} class NewB implements NewInterface {} /********************** CONVERTERS **********************/ interface ConverterInterface { public function supports(OldInterface $old): bool; public function convert(OldInterface $old): NewInterface; } class AConverter implements ConverterInterface { public function supports(OldInterface $old): bool { return $old instanceof OldA; } public function convert(OldInterface $old): NewInterface { return new NewA(); } } class BConverter implements ConverterInterface { public function supports(OldInterface $old): bool { return $old instanceof OldB; } public function convert(OldInterface $old): NewInterface { return new NewB(); } } /********************** CONVERTER DISCOVERER **********************/ interface ConverterDiscovererInterface { public function discoverConverterFor(OldInterface $old): ?ConverterInterface; } class ConverterDiscoverer implements ConverterDiscovererInterface { /** * @param ConverterInterface[] $converters */ public function __construct(private array $converters) {} public function discoverConverterFor(OldInterface $old): ?ConverterInterface { foreach ($this->converters as $converter) { if ($converter->supports($old)) { return $converter; } } return null; } } /********************** MASS CONVERTER **********************/ class MassConverter { public function __construct(private ConverterDiscovererInterface $converterDiscoverer) {} /** * @param OldInterface[] $oldObjects * @return NewInterface[] */ public function massConvert(array $oldObjects): array { $newObjects = []; foreach ($oldObjects as $oldObject) { $converter = $this->converterDiscoverer->discoverConverterFor($oldObject); if ($converter !== null) { $newObjects[] = $converter->convert($oldObject); } } return $newObjects; } } /********************** SAMPLE **********************/ $converterDiscoverer = new ConverterDiscoverer([new AConverter(), new BConverter()]); $massConverter = new MassConverter($converterDiscoverer); var_dump($massConverter->massConvert([new OldA(), new OldB()]));

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.140.0120.00917.48
8.4.130.0130.00817.63
8.4.120.0120.00822.31
8.4.110.0090.01122.57
8.4.100.0110.01520.89
8.4.90.0150.00620.70
8.4.80.0110.00817.75
8.4.70.0050.00318.03
8.4.60.0140.00719.12
8.4.50.0120.00819.71
8.4.40.0120.00919.69
8.4.30.0100.00018.94
8.4.20.0130.00718.79
8.4.10.0060.00317.83
8.3.260.0090.01116.69
8.3.250.0140.00418.88
8.3.240.0130.00719.02
8.3.230.0110.00916.82
8.3.220.0110.00917.42
8.3.210.0130.00616.82
8.3.200.0040.00416.48
8.3.190.0110.00817.37
8.3.180.0090.00516.36
8.3.170.0090.00916.54
8.3.160.0090.01018.61
8.3.150.0160.00417.36
8.3.140.0130.00716.69
8.3.130.0040.00418.32
8.3.120.0030.00620.73
8.3.110.0100.01020.94
8.3.100.0040.00424.06
8.3.90.0100.01026.77
8.3.80.0040.00416.63
8.3.70.0030.01316.75
8.3.60.0120.00318.43
8.3.50.0070.01116.64
8.3.40.0090.00918.97
8.3.30.0140.00318.84
8.3.20.0040.00424.18
8.3.10.0040.00424.66
8.3.00.0050.00226.16
8.2.290.0140.00520.49
8.2.280.0100.01018.56
8.2.270.0070.00716.86
8.2.260.0130.00718.77
8.2.250.0080.00018.36
8.2.240.0080.00018.88
8.2.230.0080.00022.58
8.2.220.0030.00637.54
8.2.210.0120.00626.77
8.2.200.0060.00316.50
8.2.190.0070.01016.63
8.2.180.0080.01225.92
8.2.170.0070.01118.91
8.2.160.0100.00322.96
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0000.01426.35
8.2.110.0030.00620.53
8.2.100.0060.00320.51
8.1.330.0130.00622.04
8.1.320.0120.00716.41
8.1.310.0080.00016.76
8.1.300.0030.00618.43
8.1.290.0040.00430.84
8.1.280.0150.00425.92
8.1.270.0000.00823.99
8.1.260.0030.00626.35
8.1.250.0040.00428.09
8.1.240.0060.00619.00
8.1.230.0070.00718.87
8.0.30.0080.01117.02
8.0.20.0110.00417.07
8.0.10.0030.01117.07
8.0.00.0070.00717.09
7.4.160.0090.00616.42
7.4.150.0100.00316.48
7.4.140.0070.00716.50
7.4.130.0000.01316.39
7.4.120.0100.00316.21
7.4.110.0060.01216.19
7.4.100.0080.00616.40
7.4.90.0130.00016.25
7.4.80.0100.00316.29
7.4.70.0070.00716.21
7.4.60.0060.00716.29
7.4.50.0060.00716.33
7.4.40.0130.00016.16
7.4.30.0090.00616.20
7.4.20.0040.01116.33
7.4.10.0140.00016.32
7.4.00.0070.00716.34
7.3.280.0090.00916.18
7.3.270.0030.01016.18
7.3.260.0070.00716.14
7.3.250.0100.00316.12
7.3.240.0080.00516.13
7.3.230.0130.00316.18
7.3.220.0060.00916.15
7.3.210.0060.00816.05
7.3.200.0030.01016.15
7.3.190.0110.01116.07
7.3.180.0000.01316.15
7.3.170.0030.01016.05
7.3.160.0070.00716.03
7.3.150.0070.00716.14
7.3.140.0110.00316.11
7.3.130.0070.00716.08
7.3.120.0070.00616.05
7.3.110.0060.01216.05
7.3.100.0100.00315.93
7.3.90.0030.01016.34
7.3.80.0100.00316.09
7.3.70.0040.01116.18
7.3.60.0070.00716.27
7.3.50.0100.00716.25
7.3.40.0100.01016.27
7.3.30.0030.01016.18
7.3.20.0060.01316.26
7.3.10.0030.01716.30
7.3.00.0030.01716.15

preferences:
76.81 ms | 403 KiB | 5 Q