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' => 30]; // 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.0060.00317.47
8.5.80.0060.00417.22
8.5.70.0070.00918.00
8.5.60.0080.00617.41
8.5.50.0110.00417.18
8.5.40.0070.00319.02
8.5.30.0100.00518.39
8.5.20.0080.00617.84
8.5.10.0100.00717.00
8.5.00.0100.00618.88
8.4.240.0120.00620.03
8.4.230.0060.00520.06
8.4.220.0080.00419.96
8.4.210.0090.00720.91
8.4.200.0110.00720.11
8.4.190.0100.00619.79
8.4.180.0150.00820.30
8.4.170.0120.00820.47
8.4.160.0110.01120.40
8.4.150.0110.00718.06
8.4.140.0120.00918.09
8.4.130.0120.00618.13
8.4.120.0100.00720.32
8.4.110.0090.00918.54
8.4.100.0130.00618.17
8.4.90.0110.00519.47
8.4.80.0120.00519.38
8.4.70.0050.00518.59
8.4.60.0160.01019.35
8.4.50.0080.00518.60
8.4.40.0070.00418.04
8.4.30.0100.00519.29
8.4.20.0100.00419.03
8.4.10.0060.00519.93
8.3.330.0070.00719.58
8.3.320.0120.00618.80
8.3.310.0080.00918.71
8.3.300.0100.00818.80
8.3.290.0090.00819.72
8.3.280.0100.00818.79
8.3.270.0120.00416.94
8.3.260.0090.00617.17
8.3.250.0090.00618.06
8.3.240.0100.00416.99
8.3.230.0080.00717.02
8.3.220.0090.00618.25
8.3.210.0060.00817.91
8.3.200.0090.00517.80
8.3.190.0080.00418.81
8.3.180.0050.00517.14
8.3.170.0130.00118.10
8.3.160.0050.00518.19
8.3.150.0090.00618.90
8.3.140.0070.00417.79
8.3.130.0070.00418.00
8.3.120.0050.00519.59
8.3.110.0050.00519.70
8.3.100.0040.00621.39
8.3.90.0060.00822.78
8.3.80.0060.00317.51
8.3.70.0060.00917.96
8.3.60.0090.00617.86
8.3.50.0110.00617.01
8.3.40.0090.00421.10
8.3.30.0120.00818.77
8.3.20.0120.00521.32
8.3.10.0080.00421.36
8.3.00.0070.00622.22
8.2.330.0150.00618.24
8.2.320.0120.00818.37
8.2.310.0090.01019.33
8.2.300.0160.00819.43
8.2.290.0080.00519.70
8.2.280.0130.00517.77
8.2.270.0120.00617.93
8.2.260.0090.00918.76
8.2.250.0080.00616.85
8.2.240.0110.00217.20
8.2.230.0120.00119.53
8.2.220.0110.00427.23
8.2.210.0090.00222.64
8.2.200.0080.00417.67
8.2.190.0080.00816.76
8.2.180.0140.00516.98
8.2.170.0130.00719.56
8.2.160.0110.00721.54
8.2.150.0110.00222.78
8.2.140.0090.00421.31
8.2.130.0070.00722.98
8.2.120.0050.00619.17
8.2.110.0130.00619.51
8.2.100.0220.00918.17
8.2.90.0250.00718.28
8.2.80.0240.00418.25
8.2.70.0250.00618.30
8.2.60.0220.00618.27
8.2.50.0210.00718.30
8.2.40.0210.01118.29
8.2.30.0210.00918.10
8.2.20.0240.00318.25
8.2.10.0180.00518.20
8.2.00.0160.00718.18
8.1.340.0120.00919.04
8.1.330.0110.00717.52
8.1.320.0110.00717.39
8.1.310.0100.00316.62
8.1.300.0130.00518.28
8.1.290.0110.00223.58
8.1.280.0100.00922.05
8.1.270.0080.00321.21
8.1.260.0080.00422.10
8.1.250.0060.00423.86
8.1.240.0080.00220.20
8.1.230.0160.00619.06
8.1.220.0170.00718.15
8.1.210.0150.00518.15
8.1.200.0150.00619.06
8.1.190.0140.00818.07
8.1.180.0140.00618.01
8.1.170.0170.00418.12
8.1.160.0130.00718.19
8.1.150.0160.00418.03
8.1.140.0170.00318.90
8.1.130.0180.00218.13
8.1.120.0170.00618.20
8.1.110.0150.00518.19
8.1.100.0190.00118.09
8.1.90.0180.00318.11
8.1.80.0170.00818.18
8.1.70.0100.00918.12
8.1.60.0170.00318.31
8.1.50.0160.00418.24
8.1.40.0110.00818.29
8.1.30.0110.00918.29
8.1.20.0180.00318.24
8.1.10.0200.00918.32
8.1.00.0190.00918.09
8.0.300.0170.00617.87
8.0.290.0180.00717.87
8.0.280.0250.00417.84
8.0.270.0170.00917.87
8.0.260.0200.00717.78
8.0.250.0170.00417.90
8.0.240.0140.00617.86
8.0.230.0110.01118.78
8.0.220.0160.00318.76
8.0.210.0220.00717.85
8.0.200.0200.00917.91
8.0.190.0220.00317.80
8.0.180.0290.00317.78
8.0.170.0280.00417.79
8.0.160.0290.00517.85
8.0.150.0240.00717.89
8.0.140.0190.00918.64
8.0.130.0240.00718.60
8.0.120.0160.00217.87
8.0.110.0140.00518.55
8.0.100.0120.00717.83
8.0.90.0180.00218.70
8.0.80.0120.00618.60
8.0.70.0140.00517.69
8.0.60.0160.00317.82
8.0.50.0140.00517.83
8.0.30.0130.00618.71
8.0.20.0150.00418.78
8.0.10.0140.00418.71

preferences:
47.11 ms | 1190 KiB | 5 Q