3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); stream_wrapper_register('fizzbuzz', FizzBuzzStreamWrapper::class); require 'fizzbuzz://1'; 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' => $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.0100.00717.18
8.5.80.0120.00617.35
8.5.70.0040.00418.84
8.5.60.0120.00617.19
8.5.50.0100.00816.82
8.5.30.0100.00819.49
8.5.20.0010.00718.75
8.5.10.0080.01016.89
8.5.00.0140.00820.25
8.4.240.0110.01020.06
8.4.230.0110.00620.04
8.4.220.0110.00820.04
8.4.210.0090.00821.75
8.4.180.0090.01320.10
8.4.170.0150.00620.55
8.4.160.0130.01120.87
8.4.150.0080.00516.93
8.4.140.0150.00717.81
8.4.130.0060.00418.00
8.4.120.0110.01020.67
8.4.110.0120.00922.61
8.4.100.0120.00618.15
8.4.90.0050.00422.44
8.4.80.0100.00719.06
8.4.70.0130.00718.90
8.4.60.0120.00918.73
8.4.50.0080.01318.72
8.4.40.0070.01417.79
8.4.30.0190.00020.55
8.4.20.0130.00719.88
8.4.10.0030.00719.70
8.3.330.0130.00820.45
8.3.320.0130.00818.82
8.3.310.0140.00618.78
8.3.300.0080.01318.82
8.3.290.0100.00720.93
8.3.280.0110.01018.65
8.3.270.0130.00716.70
8.3.260.0180.00216.62
8.3.250.0130.00618.82
8.3.240.0110.00817.00
8.3.230.0140.00516.79
8.3.220.0100.00919.27
8.3.210.0120.00718.79
8.3.200.0070.00416.85
8.3.190.0110.00417.53
8.3.180.0130.00719.29
8.3.170.0120.00616.85
8.3.160.0140.00417.36
8.3.150.0110.00718.97
8.3.140.0030.00620.74
8.3.130.0000.01018.74
8.3.120.0080.00820.66
8.3.110.0100.00320.94
8.3.100.0060.00324.06
8.3.90.0200.00026.77
8.3.80.0030.00618.68
8.3.70.0180.00416.75
8.3.60.0130.00618.39
8.3.50.0090.00916.74
8.3.40.0100.01023.84
8.3.30.0060.00919.20
8.3.20.0030.00524.18
8.3.10.0030.00624.66
8.3.00.0060.00326.16
8.2.320.0110.01018.32
8.2.310.0100.00818.32
8.2.300.0100.01020.43
8.2.290.0110.00822.13
8.2.280.0120.00618.66
8.2.270.0090.00922.70
8.2.260.0120.00617.06
8.2.250.0120.00617.11
8.2.240.0060.00617.07
8.2.230.0030.00522.58
8.2.220.0090.00037.54
8.2.210.0060.00926.77
8.2.200.0030.00616.75
8.2.190.0140.00716.88
8.2.180.0120.00325.92
8.2.170.0090.00619.16
8.2.160.0130.00722.96
8.2.150.0060.00325.66
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00419.61
8.2.110.0060.00319.04
8.2.100.0320.00418.44
8.2.90.0240.00718.44
8.2.80.0240.00618.44
8.2.70.0310.00018.44
8.2.60.0180.01418.44
8.2.50.0250.00618.44
8.2.40.0220.00918.44
8.2.30.0240.00318.44
8.2.20.0210.00718.44
8.2.10.0200.00818.44
8.2.00.0260.00718.44
8.1.340.0100.01120.24
8.1.330.0110.00820.01
8.1.320.0020.00616.48
8.1.310.0090.00616.39
8.1.300.0130.00318.75
8.1.290.0080.00430.84
8.1.280.0090.00625.92
8.1.270.0000.00824.66
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0070.00321.17
8.1.230.0250.01018.44
8.1.220.0240.00718.44
8.1.210.0200.00818.44
8.1.200.0170.01018.44
8.1.190.0250.00418.44
8.1.180.0240.00418.44
8.1.170.0210.00718.44
8.1.160.0270.00018.44
8.1.150.0200.00718.44
8.1.140.0210.00518.44
8.1.130.0260.00018.44
8.1.120.0220.00618.44
8.1.110.0270.00018.44
8.1.100.0170.00918.44
8.1.90.0240.00218.44
8.1.80.0200.00718.44
8.1.70.0190.00818.44
8.1.60.0220.00718.44
8.1.50.0260.00018.44
8.1.40.0230.00718.44
8.1.30.0220.00518.44
8.1.20.0190.00818.44
8.1.10.0220.00418.44
8.1.00.0150.00918.44
8.0.300.0180.00518.46
8.0.290.0190.01018.44
8.0.280.0250.00318.44
8.0.270.0290.00018.44
8.0.260.0350.00918.44
8.0.250.0210.00618.44
8.0.240.0170.01118.44
8.0.230.0190.00818.44
8.0.220.0320.00018.44
8.0.210.0250.00418.44
8.0.200.0250.00218.44
8.0.190.0240.00318.44
8.0.180.0260.00318.44
8.0.170.0230.00418.44
8.0.160.0190.00818.44
8.0.150.0210.00418.45
8.0.140.0280.00018.44
8.0.130.0200.00318.55
8.0.120.0190.00818.44
8.0.110.0230.00318.44
8.0.100.0210.00818.44
8.0.90.0250.00418.44
8.0.80.0240.00018.44
8.0.70.0260.00318.44
8.0.60.0220.00618.44
8.0.50.0290.00018.44
8.0.30.0160.01218.44
8.0.20.0230.00618.44
8.0.10.0210.00718.44

preferences:
92.58 ms | 1136 KiB | 5 Q