3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); stream_wrapper_register('fizzbuzz', FizzBuzzStreamWrapper::class); require 'fizzbuzz://22'; 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 { 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 { if ($this->counter > $this->length) { return false; } $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 { return true; } public function stream_eof(): bool { return $this->counter ===$this->length; } public function stream_stat(): array|false { return ['size' => 0]; // return ['size' => $this->getSize()]; } public function stream_set_option(int $option, int $arg1, int $arg2) { 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.00817.50
8.5.80.0090.00917.47
8.5.70.0050.00719.14
8.5.60.0060.00217.49
8.5.50.0110.00817.19
8.5.30.0100.00919.59
8.5.20.0120.00718.47
8.5.10.0120.00716.84
8.5.00.0130.00920.51
8.4.240.0130.01020.07
8.4.230.0170.00620.04
8.4.220.0100.01020.09
8.4.210.0130.00821.73
8.4.180.0140.00819.89
8.4.170.0110.01020.66
8.4.160.0140.00720.80
8.4.150.0080.00517.05
8.4.140.0110.01117.88
8.4.130.0080.00318.89
8.4.120.0110.00923.83
8.4.110.0140.00620.84
8.4.100.0120.01018.91
8.4.90.0170.00418.96
8.4.80.0060.00518.12
8.4.70.0030.00618.29
8.4.60.0110.01018.73
8.4.50.0110.01119.99
8.4.40.0160.00617.93
8.4.30.0140.00720.56
8.4.20.0070.01120.16
8.4.10.0030.01719.69
8.3.330.0130.00920.71
8.3.320.0060.00418.88
8.3.310.0090.00918.79
8.3.300.0110.01018.81
8.3.290.0120.00820.70
8.3.280.0130.00718.81
8.3.270.0100.00916.68
8.3.260.0090.00717.23
8.3.250.0070.00418.82
8.3.240.0130.00717.39
8.3.230.0130.00816.86
8.3.220.0090.00718.98
8.3.210.0100.00916.96
8.3.200.0050.00416.96
8.3.190.0100.00916.79
8.3.180.0140.00519.06
8.3.170.0040.00417.22
8.3.160.0070.00018.50
8.3.150.0100.01020.85
8.3.140.0080.00818.78
8.3.130.0080.00018.49
8.3.120.0060.00318.92
8.3.110.0100.00718.81
8.3.100.0130.00616.90
8.3.90.0080.00026.77
8.3.80.0040.00418.55
8.3.70.0040.01118.68
8.3.60.0070.00716.88
8.3.50.0160.00616.91
8.3.40.0140.00323.61
8.3.30.0040.01419.34
8.3.20.0040.00424.18
8.3.10.0030.00524.66
8.3.00.0080.00026.16
8.2.320.0150.00518.28
8.2.310.0150.00518.38
8.2.300.0090.01320.46
8.2.290.0080.00720.57
8.2.280.0150.00617.19
8.2.270.0130.00617.18
8.2.260.0080.00020.75
8.2.250.0120.00318.94
8.2.240.0070.01017.23
8.2.230.0000.00920.94
8.2.220.0040.00424.06
8.2.210.0050.00326.77
8.2.200.0040.00416.88
8.2.190.0130.00618.91
8.2.180.0040.01816.75
8.2.170.0110.00419.16
8.2.160.0070.01322.96
8.2.150.0000.00825.66
8.2.140.0050.00324.66
8.2.130.0000.00826.16
8.2.120.0060.00321.17
8.2.110.0060.00319.45
8.2.100.0320.00718.44
8.2.90.0240.00718.44
8.2.80.0210.00718.44
8.2.70.0220.00318.44
8.2.60.0230.00318.44
8.2.50.0220.00818.44
8.2.40.0160.00318.44
8.2.30.0150.00818.44
8.2.20.0190.00318.44
8.2.10.0210.00018.44
8.2.00.0170.00418.44
8.1.340.0120.00920.31
8.1.330.0110.01021.85
8.1.320.0120.00916.32
8.1.310.0040.00416.77
8.1.300.0070.00318.08
8.1.290.0050.00530.84
8.1.280.0120.00625.92
8.1.270.0100.01023.86
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00022.66
8.1.230.0160.01018.44
8.1.220.0150.01018.44
8.1.210.0190.00418.44
8.1.200.0230.00018.44
8.1.190.0190.00418.44
8.1.180.0150.00818.44
8.1.170.0070.01518.44
8.1.160.0190.00318.44
8.1.150.0200.00318.44
8.1.140.0090.01118.44
8.1.130.0150.00918.44
8.1.120.0150.00718.44
8.1.110.0260.00318.44
8.1.100.0160.00618.44
8.1.90.0210.00318.44
8.1.80.0170.00918.44
8.1.70.0170.00618.44
8.1.60.0150.00618.44
8.1.50.0160.00418.44
8.1.40.0110.01118.44
8.1.30.0110.01118.44
8.1.20.0250.00018.44
8.1.10.0240.00018.44
8.1.00.0170.00818.44
8.0.300.0180.00018.44
8.0.290.0200.00718.44
8.0.280.0170.00818.44
8.0.270.0170.00618.44
8.0.260.0170.00318.44
8.0.250.0160.00618.44
8.0.240.0100.01518.44
8.0.230.0210.00318.44
8.0.220.0150.00718.44
8.0.210.0130.01018.44
8.0.200.0090.01318.44
8.0.190.0150.00918.44
8.0.180.0070.01518.44
8.0.170.0180.00518.44
8.0.160.0120.00818.44
8.0.150.0120.00618.44
8.0.140.0180.00418.44
8.0.130.0200.00018.44
8.0.120.0170.00318.44
8.0.110.0190.00418.44
8.0.100.0140.00918.44
8.0.90.0270.00218.44
8.0.80.0190.00318.44
8.0.70.0160.01018.44
8.0.60.0190.00518.44
8.0.50.0180.00718.44
8.0.30.0150.00918.44
8.0.20.0190.00518.44
8.0.10.0140.00718.44

preferences:
45.72 ms | 1169 KiB | 5 Q