3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace Acme\FizzBuzz; use Generator; /** * Create a sequence of numbers and words that match the current offset. * * @param array<int,string> $dictionary * @param int $start * @param int $size * @param int $step * @param int $modulo * * @yield string * @return Generator */ function createSequence( array $dictionary, int $start, int $size, int $step = 1, int $modulo = 0 ): Generator { for ($index = $start; $index <= $size; $index += $step) { $entry = ''; foreach ($dictionary as $offset => $word) { if ($index % $offset === $modulo) { $entry .= $word; } } yield $entry === '' ? $index : $entry; } } // Write a short program that prints each number from 1 to 100. // For each multiple of 3, print "Fizz" instead of the number. // For each multiple of 5, print "Buzz" instead of the number. // For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number. $sequence = \Acme\FizzBuzz\createSequence( [ 3 => 'Fizz', 5 => 'Buzz' ], 1, 100 ); foreach ($sequence as $entry) { echo $entry . PHP_EOL; }

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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.2.110.0060.01116.39
7.2.100.0080.00516.39
7.2.90.0040.01116.71
7.2.80.0060.00916.64
7.2.70.0120.00316.65
7.2.60.0060.00916.99
7.2.50.0090.00316.88
7.2.40.0140.00317.04
7.2.30.0100.00517.09
7.2.20.0100.00316.84
7.2.10.0090.00617.01
7.2.00.0000.01316.98
7.1.230.0110.00615.68
7.1.220.0030.01115.74
7.1.210.0000.01415.60
7.1.200.0030.00915.60
7.1.190.0090.00315.79
7.1.180.0070.00715.73
7.1.170.0030.00915.81
7.1.160.0040.00715.66
7.1.150.0060.00615.77
7.1.140.0110.00315.61
7.1.130.0030.00915.78
7.1.120.0060.00615.90
7.1.110.0040.00815.54
7.1.100.0040.01115.83
7.1.90.0130.00315.69
7.1.80.0070.00715.88
7.1.70.0000.01215.93
7.1.60.0230.01333.82
7.1.50.0210.01033.72
7.1.40.0190.01333.96
7.1.30.0190.01333.59
7.1.20.0220.00933.92
7.1.10.0030.01015.91
7.1.00.0080.00815.96
7.0.280.0040.01115.16
5.6.380.0120.00013.89