TestPrimes.php

  1. <?php // $ php TestPrimes.php
  2.  
  3. ini_set('display_errors', 1);
  4. header ("Content-Type: text/plain");
  5.  
  6. include "Primes.php";
  7.  
  8. $start = microtime(true);
  9.  
  10. $count = 0;
  11. $primes = new Primes();
  12. while ($primes->hasNext()) {
  13. $prime = $primes->next();
  14. $count++;
  15. if (($count % 1e6) == 0) echo ($count/1e6)." ";
  16. }
  17. $primes->close();
  18. echo "\nCOUNT=$count\n";
  19.  
  20. $elapsed = round(microtime(true) - $start, 2);
  21. echo "ELAPSED=$elapsed segundos\n"; // 25 segundos
  22.  
  23. /*
  24. Ejemplo:
  25. $ php TestPrimes.php
  26. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  27. COUNT=50000000
  28. ELAPSED=35.95 segundos
  29. */
  30.  

Proinf.net