Skip to content

Instantly share code, notes, and snippets.

@romanitalian
Created December 5, 2020 10:46
Show Gist options
  • Save romanitalian/dcd3d581c7b70464d625cc1567daeb59 to your computer and use it in GitHub Desktop.
Save romanitalian/dcd3d581c7b70464d625cc1567daeb59 to your computer and use it in GitHub Desktop.
<?php
function isPrime($num)
{
if ($num == 2) {
return true;
}
if ($num == 1 || $num %2 == 0) {
return false;
}
$to = sqrt($num) + 1;
for ($i = 3; $i <= $to; $i += 2) {
if ($num % $i == 0) {
return false;
}
}
return true;
}
function run($N)
{
for ($i = 0; $i <= $N; $i++) {
$isPrime = isPrime($i);
// if ($isPrime) {
// var_dump($i);
// }
}
}
function main()
{
$st = microtime(true);
run(10000000);
echo microtime(true) - $st;
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment