Skip to content

Instantly share code, notes, and snippets.

@gutoccs
Last active November 1, 2018 18:29
Show Gist options
  • Save gutoccs/de66d3607556eb423df4335b98eee726 to your computer and use it in GitHub Desktop.
Save gutoccs/de66d3607556eb423df4335b98eee726 to your computer and use it in GitHub Desktop.
Cálculo de los números primos que hay hasta un entero n
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cálculo de los números primos que hay hasta un número n</title>
</head>
<body>
<?php
$inicio = microtime(true);
$numero = 0;
$divisor = 0;
$n = 100000;
$esPrimo = 0;
for ($numero=2; $numero<=$n; $numero++) {
$esPrimo=1;
for ($divisor=2; $divisor<=sqrt($numero); $divisor++) {
if ($numero%$divisor==0) {
$esPrimo=0;
break;
}
}
//if($esPrimo==1) echo $numero."<br>";
}
$tiempo = microtime(true) - $inicio;
echo 'fin';
echo "<br>".'Tiempo Total: ' . $tiempo . ' segundos.';
?>
</body>
</html>
@gutoccs
Copy link
Author

gutoccs commented Nov 26, 2017

Código usado en mi Blog gutoccs.wordpress.com para el artículo Comparando el rendimiento de 3 versiones de PHP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment