3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Trial division function generatePrimesA($n) { $primes = [2]; for ($i = 3; $i < $n; $i += 2) { foreach ($primes as $prime) { if ($i % $prime == 0) { continue 2; } } $primes[] = $i; } return $primes; } // Sieve of Eratosthenes function generatePrimesB($max) { $primes = array_fill(2, $max - 1, true); for ($i = 2; pow($i, 2) < $max; $i++) { if ($primes[$i]) { for ($j = $i * $i; $j <= $max; $j += $i) { $primes[$j] = false; } } } return array_keys(array_filter($primes)); } // $a = microtime(1); // var_dump(count(generatePrimesA(100000))); // $a = microtime(1) - $a; $b = microtime(1); var_export(count(generatePrimesB(100000))); $b = microtime(1) - $b; // var_dump($a); var_dump($b);
Output for 7.1.0
9592float(0.0081479549407959)
Output for 7.0.14
9592float(0.0088930130004883)
Output for 7.0.6
9592float(0.007080078125)
Output for 7.0.5
9592float(0.009613037109375)
Output for 7.0.4
9592float(0.0064990520477295)
Output for 7.0.3
9592float(0.016534805297852)
Output for 7.0.2
9592float(0.011685848236084)
Output for 7.0.1
9592float(0.0065510272979736)
Output for 7.0.0
9592float(0.0078220367431641)
Output for hhvm-3.12.0
9592float(0.022278070449829)
Output for hhvm-3.10.0
9592float(0.027567863464355)
Output for 5.6.28
9592float(0.045093059539795)
Output for 5.6.21
9592float(0.034837961196899)
Output for 5.6.20
9592float(0.028190851211548)
Output for 5.6.19
9592float(0.041803121566772)
Output for 5.6.18
9592float(0.037929773330688)
Output for 5.6.17
9592float(0.031594038009644)
Output for 5.6.16
9592float(0.032299041748047)
Output for 5.6.15
9592float(0.042428016662598)
Output for 5.6.14
9592float(0.036059856414795)
Output for 5.6.13
9592float(0.038685083389282)
Output for 5.6.12
9592float(0.035768032073975)
Output for 5.6.11
9592float(0.038779020309448)
Output for 5.6.10
9592float(0.032367944717407)
Output for 5.6.9
9592float(0.03171181678772)
Output for 5.6.8
9592float(0.038640022277832)
Output for 5.5.35
9592float(0.028491973876953)
Output for 5.5.34
9592float(0.04378604888916)
Output for 5.5.33
9592float(0.040370941162109)
Output for 5.5.32
9592float(0.035952806472778)
Output for 5.5.31
9592float(0.040076017379761)
Output for 5.5.30
9592float(0.031046867370605)
Output for 5.5.29
9592float(0.039719820022583)
Output for 5.5.28
9592float(0.031546115875244)
Output for 5.5.27
9592float(0.036418199539185)
Output for 5.5.26
9592float(0.042472839355469)
Output for 5.5.25
9592float(0.049998998641968)
Output for 5.5.24
9592float(0.025162935256958)
Output for 5.4.45
9592float(0.029011964797974)
Output for 5.4.44
9592float(0.029870986938477)
Output for 5.4.43
9592float(0.029776811599731)
Output for 5.4.42
9592float(0.028643131256104)
Output for 5.4.41
9592float(0.02910590171814)
Output for 5.4.40
9592float(0.035274982452393)
Output for 5.4.39
9592float(0.029535055160522)
Output for 5.4.38
9592float(0.02864408493042)
Output for 5.4.37
9592float(0.029232978820801)
Output for 5.4.36
9592float(0.029555082321167)
Output for 5.4.35
9592float(0.029278993606567)
Output for 5.4.34
9592float(0.028974056243896)
Output for 5.4.32
9592float(0.029361009597778)
Output for 5.4.31
9592float(0.028773784637451)
Output for 5.4.30
9592float(0.030058145523071)
Output for 5.4.29
9592float(0.028475999832153)
Output for 5.4.28
9592float(0.028413057327271)
Output for 5.4.27
9592float(0.034626960754395)
Output for 5.4.26
9592float(0.028702974319458)
Output for 5.4.25
9592float(0.029948949813843)
Output for 5.4.24
9592float(0.030658960342407)
Output for 5.4.23
9592float(0.028020858764648)
Output for 5.4.22
9592float(0.027904033660889)
Output for 5.4.21
9592float(0.034131050109863)
Output for 5.4.20
9592float(0.028419017791748)
Output for 5.4.19
9592float(0.029368162155151)
Output for 5.4.18
9592float(0.028468132019043)
Output for 5.4.17
9592float(0.02796196937561)
Output for 5.4.16
9592float(0.028036117553711)
Output for 5.4.15
9592float(0.027873992919922)
Output for 5.4.14
9592float(0.028836965560913)
Output for 5.4.13
9592float(0.028069972991943)
Output for 5.4.12
9592float(0.028170108795166)
Output for 5.4.11
9592float(0.032570123672485)
Output for 5.4.10
9592float(0.047307014465332)
Output for 5.4.9
9592float(0.0294029712677)
Output for 5.4.8
9592float(0.029430866241455)
Output for 5.4.7
9592float(0.033083915710449)
Output for 5.4.6
9592float(0.029761075973511)
Output for 5.4.5
9592float(0.030736923217773)
Output for 5.4.4
9592float(0.030420064926147)
Output for 5.4.3
9592float(0.030886888504028)
Output for 5.4.2
9592float(0.030318975448608)
Output for 5.4.1
9592float(0.030032873153687)
Output for 5.4.0
9592float(0.031320095062256)
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/FApHl on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/FApHl on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/FApHl on line 5
Process exited with code 255.