3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class StringObject { protected string $string; public function __toString(): string { return $this->string; } } class StringObjectException extends Exception { public readonly string $string; public function __construct(string $string, string $message = "", int $code = 0, Throwable $previous = null) { parent::__construct($message, $code, $previous); $this->string = $string; } } class CountableString extends StringObject { private int $lettersCount; public function __construct(string $string) { $this->string = $string; $this->lettersCount = mb_strlen($string); } public function countLetters(): int { return $this->lettersCount; } } class EmptyStringException extends StringObjectException {} class NotEmptyString extends StringObject { /** * @throws EmptyStringException */ public function __construct(string $string) { if ('' === $string) { throw new EmptyStringException(string: $string, message: 'Expected not empty string.'); } $this->string = $string; } } class TooLongStringException extends StringObjectException {} class LimitedLengthString extends StringObject { /** * @throws TooLongStringException */ public function __construct(CountableString $string, int $maxLength) { if ($maxLength < $string->countLetters()) { throw new TooLongStringException(string: $string, message: 'Too long string'); } $this->string = $string; } } class TenLettersStringValidator { private const MAX_LETTERS_COUNT = 10; private const ERROR_MESSAGE = 'Expected string not longer then: "%d letters" got: "%s"'; public function __invoke(string $string): ?string { $error = null; try { new LimitedLengthString(new CountableString($string), self::MAX_LETTERS_COUNT); } catch (TooLongStringException $exception) { $error = sprintf(self::ERROR_MESSAGE, self::MAX_LETTERS_COUNT, $exception->string ); } return $error; } } $validators = [new TenLettersStringValidator]; $errors = []; $string = 'Тестовая строка'; foreach ($validators as $validator) { $result = $validator($string); $result ? $errors[] = $result : null; } var_dump($errors);

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.0090.00820.64
8.4.110.0040.00422.50
8.4.100.0090.00917.98
8.4.90.0120.00918.57
8.4.80.0050.00418.17
8.4.70.0080.01118.16
8.4.60.0100.01018.99
8.4.50.0100.01118.60
8.4.40.0140.00717.89
8.4.30.0060.01318.71
8.4.20.0130.00718.29
8.4.10.0090.00919.79
8.3.250.0040.00418.80
8.3.240.0120.00817.18
8.3.230.0070.00416.87
8.3.220.0110.00517.34
8.3.210.0090.00616.57
8.3.200.0040.00416.71
8.3.190.0100.00517.28
8.3.180.0100.00918.59
8.3.170.0060.01220.65
8.3.160.0090.00917.34
8.3.150.0130.00616.92
8.3.140.0110.00716.63
8.3.130.0110.00018.31
8.3.120.0000.01018.96
8.3.110.0040.00418.39
8.3.100.0090.00018.34
8.3.50.0110.00418.31
8.3.00.0060.01219.02
8.2.290.0120.00720.67
8.2.280.0090.01020.37
8.2.270.0110.00819.08
8.2.260.0080.01216.97
8.2.250.0000.00816.76
8.2.240.0060.00317.18
8.2.230.0090.00618.31
8.2.220.0060.00918.50
8.2.130.0150.00318.09
8.2.120.0110.00717.63
8.2.110.0120.00917.75
8.2.100.0040.01117.50
8.2.90.0140.00717.88
8.2.80.0120.00319.36
8.2.70.0110.00417.75
8.2.60.0150.00317.63
8.2.50.0050.00317.75
8.2.40.0060.00317.75
8.2.30.0150.00417.75
8.2.20.0050.00317.75
8.2.10.0110.00717.63
8.2.00.0060.00317.75
8.1.330.0100.00921.79
8.1.320.0120.00815.98
8.1.310.0180.00016.97
8.1.300.0000.00818.58
8.1.260.0050.00317.48
8.1.250.0120.00317.48
8.1.240.0100.00017.36
8.1.230.0060.00317.36
8.1.220.0070.00317.47
8.1.210.0070.00317.36
8.1.200.0000.01117.35
8.1.190.0030.00717.36
8.1.180.0060.00317.35
8.1.170.0050.00317.35
8.1.160.0050.00317.22
8.1.150.0030.00517.34
8.1.140.0040.00417.35
8.1.130.0030.00517.35
8.1.120.0030.00617.35
8.1.110.0080.00017.34
8.1.100.0000.00817.35
8.1.90.0050.00317.35
8.1.80.0060.00317.23
8.1.70.0030.00617.34
8.1.60.0060.00317.60
8.1.50.0000.00817.59
8.1.40.0000.00817.47
8.1.30.0000.00817.59
8.1.20.0040.00417.72
8.1.10.0040.00417.72
8.1.00.0000.00817.47
8.0.300.0040.00416.63
8.0.290.0070.00016.50
8.0.280.0040.00416.63
8.0.270.0030.00616.63
8.0.260.0050.00516.63
8.0.250.0030.00616.75
8.0.240.0000.00816.75
8.0.230.0040.00416.63
8.0.220.0000.00716.63
8.0.210.0040.00416.75
8.0.200.0040.00416.75
8.0.190.0080.00016.75
8.0.180.0040.00416.75
8.0.170.0040.00416.75
8.0.160.0040.00416.75
8.0.150.0030.00616.63
8.0.140.0080.00016.63
8.0.130.0040.00416.63
8.0.120.0000.00716.63
8.0.110.0040.00416.63
8.0.100.0030.00516.75
8.0.90.0040.00416.63
8.0.80.0080.00016.63
8.0.70.0040.00416.63
8.0.60.0050.00216.50
8.0.50.0000.00816.63
8.0.30.0070.00016.75
8.0.20.0040.00416.75
8.0.10.0000.00816.75

preferences:
47.86 ms | 403 KiB | 5 Q