3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace Metadata; class ClassMetadata implements \Serializable { /** * @var string */ public $name; /** * @var MethodMetadata[] */ public $methodMetadata = []; /** * @var PropertyMetadata[] */ public $propertyMetadata = []; /** * @var string[] */ public $fileResources = []; /** * @var int */ public $createdAt; public function __construct(string $name) { $this->name = $name; $this->createdAt = time(); } public function addMethodMetadata(MethodMetadata $metadata): void { $this->methodMetadata[$metadata->name] = $metadata; } public function addPropertyMetadata(PropertyMetadata $metadata): void { $this->propertyMetadata[$metadata->name] = $metadata; } public function isFresh(?int $timestamp = null): bool { if (null === $timestamp) { $timestamp = $this->createdAt; } foreach ($this->fileResources as $filepath) { if (!file_exists($filepath)) { return false; } if ($timestamp < filemtime($filepath)) { return false; } } return true; } /** * @return string * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation */ public function serialize() { return serialize($this->__serialize()); } /** * @param string $str * * @return void * * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.UselessReturnAnnotation */ public function unserialize($str) { $this->__unserialize(unserialize($str)); } /** * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification */ public function __serialize(): array { return [ $this->name, $this->methodMetadata, $this->propertyMetadata, $this->fileResources, $this->createdAt, ]; } /** * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification */ public function __unserialize(array $data): void { [ $this->name, $this->methodMetadata, $this->propertyMetadata, $this->fileResources, $this->createdAt, ] = $data; } } namespace Massive\Bundle\SearchBundle\Search\Metadata; use Metadata\ClassMetadata as BaseClassMetadata; class ClassMetadata2 extends BaseClassMetadata implements \Serializable { /** * @var array */ private $indexMetadatas = []; /** * @var string */ private $repositoryMethod; /** * Add an index metadata for the given context name. * * @param mixed $contextName */ public function addIndexMetadata($contextName, IndexMetadata $indexMetadata) { if (isset($this->indexMetadatas[$contextName])) { throw new \InvalidArgumentException(\sprintf( 'Context name "%s" has already been registered', $contextName )); } $indexMetadata->setName($this->name); $indexMetadata->setClassMetadata($this); $this->indexMetadatas[$contextName] = $indexMetadata; } /** * Return the IndexMetadata metadata instances. * * @return IndexMetadata[] */ public function getIndexMetadatas() { return $this->indexMetadatas; } /** * Return the indexmetadata for the given context. * * @param string $contextName * * @return IndexMetadata */ public function getIndexMetadata($contextName) { if (!isset($this->indexMetadatas[$contextName])) { throw new \InvalidArgumentException(\sprintf( 'Context name "%s" not known, known contexts: "%s"', $contextName, \implode('", "', \array_keys($this->indexMetadatas)) )); } return $this->indexMetadatas[$contextName]; } public function serialize() { $data = parent::serialize(); return [$data, \serialize($this->indexMetadatas), $this->repositoryMethod]; } public function unserialize($data) { list($data, $indexMetadata, $this->repositoryMethod) = \unserialize($data); parent::unserialize($data); $this->indexMetadatas = \unserialize($indexMetadata); } public function __serialize(): array { return $this->serialize(); } public function __unserialize(array $data): void { $this->unserialize($data); } /** * If specified, the reindex repsoitory method will be used to indicate a method * which can be used to modify the query builder (e.g. to exclude certain objects * from the index). * * @deprecated Returning anything from this method is deprecated. It will be passed a query builder */ public function getReindexRepositoryMethod() { return $this->repositoryMethod; } /** * Set the repository method which should be used when reindexing. * * @param string $repositoryMethod */ public function setReindexRepositoryMethod($repositoryMethod) { $this->repositoryMethod = $repositoryMethod; } } namespace App; class TestClass { } $test = new \Metadata\ClassMetadata(TestClass::class); $test2 = new \Massive\Bundle\SearchBundle\Search\Metadata\ClassMetadata2(TestClass::class); $string = serialize($test); unserialize($string); $string2 = serialize($test2); unserialize($string2);

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.0.130.0400.01672.38
8.0.120.0490.00672.54
8.0.110.0450.00872.43
8.0.100.0400.01472.45
8.0.90.0390.01672.61
8.0.80.0460.01172.50
8.0.70.0430.01372.39
8.0.60.0470.00572.42
8.0.50.0440.01172.56
8.0.30.0480.00772.43
8.0.20.0400.01672.59
8.0.10.0490.00872.61
8.0.00.0400.01272.47
7.4.260.0280.01471.89
7.4.250.0520.01472.11
7.4.240.0510.01072.10
7.4.230.0520.01072.04
7.4.220.0420.01672.08
7.4.210.0440.01472.04
7.4.200.0500.00772.03
7.4.190.0430.01272.13
7.4.180.0480.01272.13
7.4.160.0280.02072.20
7.4.150.0430.00772.08
7.4.140.0300.01872.04
7.4.130.0430.00872.05
7.4.120.0370.01272.02
7.4.110.0350.01472.03
7.4.100.0400.01172.04
7.4.90.0390.01172.12
7.4.80.0390.01172.01
7.4.70.0420.01072.05
7.4.60.0390.01172.04
7.4.50.0380.01171.98
7.4.40.0380.01371.97
7.4.30.0370.01072.11
7.4.20.0380.01271.98
7.4.10.0340.01472.05
7.4.00.0300.01471.98
7.3.330.0320.01271.81
7.3.320.0230.02471.81
7.3.310.0330.01271.91
7.3.300.0260.01871.94
7.3.290.0270.01871.82
7.3.280.0320.01472.02
7.3.270.0320.01171.88
7.3.260.0350.01171.86
7.3.250.0250.02271.87
7.3.240.0370.00971.90
7.3.230.0420.00871.98
7.3.220.0400.00871.92
7.3.210.0400.01071.87
7.3.200.0350.01271.84
7.3.190.0290.01771.83
7.3.180.0320.01471.71
7.3.170.0370.01071.78
7.3.160.0330.01271.93
7.3.150.0350.01271.87
7.3.140.0340.01271.83
7.3.130.0350.01371.82
7.3.120.0340.01071.67
7.3.110.0320.01471.85
7.3.100.0310.01571.64
7.3.90.0390.00871.97
7.3.80.0260.02171.71
7.3.70.0370.00572.00
7.3.60.0300.01671.95
7.3.50.0330.01471.84
7.3.40.0320.01572.02
7.3.30.0360.01071.94
7.3.20.0620.01280.07
7.3.10.0100.01580.07
7.3.00.0170.01180.02

preferences:
34.87 ms | 403 KiB | 5 Q