3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); set_time_limit(1); stream_wrapper_register('fizzbuzz', FizzBuzzStreamWrapper::class); require 'fizzbuzz://3'; final class FizzBuzzStreamWrapper { private int $counter = 1; private int $length = 15; /** @var resource */ public $context; public function stream_open(string $path, $mode, $options, &$opened_path): bool { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; preg_match('#([\d]+$)#', $path, $matches); $this->length = filter_var( $matches[1] ?? '', FILTER_VALIDATE_INT, ['options' => ['default' => 15]] ); return true; } public function stream_read($count): string|false { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; echo "\tcurrent counter: {$this->counter}" . PHP_EOL; $fizzbuzz = match (true) { $this->counter % 15 === 0 => 'FizzBuzz', $this->counter % 5 === 0 => 'Buzz', $this->counter % 3 === 0 => 'Fizz', default => (string)$this->counter }; $contents = ''; if ($this->counter === 1) { $contents = '<?php ' . PHP_EOL; } $contents .= "echo '{$fizzbuzz}' . PHP_EOL;"; $this->counter++; return $contents; } public function stream_close(): bool { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return true; } public function stream_eof(): bool { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; echo "\tcurrent counter: {$this->counter}" . PHP_EOL; return $this->counter ===$this->length; } public function stream_stat(): array|false { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return ['size' => $this->getSize()]; } public function stream_set_option(int $option, int $arg1, int $arg2) { echo 'called `' . __METHOD__ . '` with ' . json_encode(func_get_args()) . PHP_EOL; return false; } private function getSize() { $ret = strlen("<?php \n") + $this->length * 18; $range = range(1, $this->length); $numbers = array_filter($range, fn ($n) => ($n % 3 !== 0 && $n % 5 !== 0)); $ret += strlen(implode('', $numbers)); $fizzOrBuzzs = array_filter($range, fn ($n) => ($n % 15 !== 0) && ($n % 3 === 0 || $n % 5 === 0)); $ret += strlen('fizz') * count($fizzOrBuzzs); $fizzbuzzs = array_filter($range, fn ($n) => ($n % 15 === 0)); $ret += strlen('fizzbuzz') * count($fizzbuzzs); return $ret; } }

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.5.90.0090.01017.44
8.5.80.0060.00317.26
8.5.70.0100.01017.11
8.5.60.0120.00617.30
8.5.50.0020.00517.01
8.5.30.0110.00719.60
8.5.20.0090.00918.88
8.5.10.0130.00616.95
8.5.00.0090.01320.32
8.4.240.0130.00920.04
8.4.230.0140.00719.80
8.4.220.0070.00520.05
8.4.210.0110.01021.71
8.4.180.0150.00719.82
8.4.170.0150.00820.54
8.4.160.0140.00822.39
8.4.150.0080.00617.05
8.4.140.0150.00617.86
8.4.130.0130.00817.87
8.4.120.0100.01122.19
8.4.110.0110.01022.18
8.4.100.0090.01120.66
8.4.90.0110.01119.00
8.4.80.0140.00618.73
8.4.70.0110.00818.03
8.4.60.0090.00919.01
8.4.50.0110.01319.62
8.4.40.0060.00318.00
8.4.30.0160.00319.11
8.4.20.0000.00920.00
8.4.10.0060.00319.93
8.3.330.0100.00820.66
8.3.320.0110.00418.72
8.3.310.0120.01118.76
8.3.300.0170.00519.00
8.3.290.0110.01120.83
8.3.280.0130.00718.65
8.3.270.0170.00817.06
8.3.260.0030.00616.79
8.3.250.0100.01019.05
8.3.240.0120.00716.57
8.3.230.0090.01017.10
8.3.220.0060.00217.31
8.3.210.0110.01018.41
8.3.200.0020.00716.65
8.3.190.0090.01117.11
8.3.180.0070.01219.27
8.3.170.0110.00717.23
8.3.160.0150.00418.73
8.3.150.0110.00420.88
8.3.140.0150.00417.11
8.3.130.0080.00018.36
8.3.120.0090.00020.86
8.3.110.0060.00618.73
8.3.100.0050.00316.87
8.3.90.0060.00926.77
8.3.80.0070.00418.55
8.3.70.0110.01118.68
8.3.60.0110.00816.88
8.3.50.0100.00616.97
8.3.40.0090.00923.66
8.3.30.0100.00719.29
8.3.20.0000.00824.18
8.3.10.0060.00324.66
8.3.00.0050.00326.16
8.2.320.0110.01018.58
8.2.310.0100.01118.51
8.2.300.0110.00920.46
8.2.290.0100.01020.62
8.2.280.0100.00920.52
8.2.270.0040.00417.34
8.2.260.0040.01420.52
8.2.250.0000.00917.53
8.2.240.0060.00617.41
8.2.230.0140.00720.94
8.2.220.0000.01024.06
8.2.210.0080.00026.77
8.2.200.0050.00517.00
8.2.190.0170.00318.54
8.2.180.0090.00616.63
8.2.170.0110.01119.26
8.2.160.0170.00022.96
8.2.150.0080.00025.66
8.2.140.0120.00324.66
8.2.130.0040.00426.16
8.2.120.0000.00821.25
8.2.110.0070.00419.43
8.2.100.0310.00518.44
8.2.90.0240.00718.44
8.2.80.0270.00318.44
8.2.70.0230.00918.44
8.2.60.0260.00318.44
8.2.50.0240.00718.44
8.2.40.0280.00318.44
8.2.30.0270.00718.44
8.2.20.0200.00918.44
8.2.10.0230.00618.44
8.2.00.0260.00418.44
8.1.340.0110.00920.31
8.1.330.0060.01121.99
8.1.320.0070.01216.55
8.1.310.0100.01016.78
8.1.300.0100.00716.50
8.1.290.0060.00330.84
8.1.280.0070.00725.92
8.1.270.0060.00323.91
8.1.260.0030.00526.35
8.1.250.0000.00828.09
8.1.240.0030.00622.77
8.1.230.0250.00918.44
8.1.220.0210.01318.44
8.1.210.0270.00018.44
8.1.200.0240.00418.44
8.1.190.0180.00918.44
8.1.180.0270.00018.44
8.1.170.0140.01418.44
8.1.160.0240.00318.44
8.1.150.0230.00818.44
8.1.140.0290.00018.44
8.1.130.0240.00418.44
8.1.120.0230.00318.44
8.1.110.0270.00018.44
8.1.100.0270.00018.44
8.1.90.0170.00918.44
8.1.80.0210.00718.44
8.1.70.0180.00918.44
8.1.60.0230.00318.44
8.1.50.0190.00518.44
8.1.40.0170.00718.44
8.1.30.0210.00618.44
8.1.20.0200.01018.44
8.1.10.0240.00318.44
8.1.00.0120.01218.44
8.0.300.0170.00418.65
8.0.290.0290.00018.44
8.0.280.0230.00418.44
8.0.270.0290.00018.44
8.0.260.0230.00818.44
8.0.250.0240.00318.44
8.0.240.0310.00318.44
8.0.230.0260.00318.44
8.0.220.0240.00518.44
8.0.210.0220.00718.44
8.0.200.0260.00518.44
8.0.190.0210.00618.44
8.0.180.0250.00318.44
8.0.170.0210.00618.44
8.0.160.0210.00618.44
8.0.150.0220.00018.48
8.0.140.0240.00318.44
8.0.130.0220.00418.73
8.0.120.0240.00618.44
8.0.110.0270.00018.44
8.0.100.0250.00418.44
8.0.90.0200.00718.44
8.0.80.0220.00318.44
8.0.70.0170.01018.44
8.0.60.0200.00618.44
8.0.50.0280.00018.44
8.0.30.0220.00618.44
8.0.20.0180.00918.44
8.0.10.0220.00518.44

preferences:
51.82 ms | 1255 KiB | 5 Q