Don't like ads? PRO users don't see any ads ;-)
Guest

Javascript random number generation benchmark

By: DaveRandom on Jun 14th, 2012  |  syntax: JavaScript  |  size: 0.58 KB  |  hits: 31  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Javascript random number generation code (speedtest benchmark)
  2. // See: http://stackoverflow.com/questions/11040131/random-number-generation-speed
  3. // See: http://pastebin.com/BUEZUn7f
  4.  
  5. var iterations, i, rand, start, randTime;
  6.  
  7. iterations = 10000000;
  8.  
  9.   // ============================
  10.  
  11. i = rand = start = randTime = 0;
  12.  
  13. start = Date.now();
  14. while (i++ < iterations) {
  15.   rand = Math.random();
  16. }
  17. randTime = (Date.now() - start) / 1000;
  18.  
  19.   // ============================
  20.  
  21. console.log("\n" +
  22. "   Iterations: " + iterations + "\n" +
  23. "   Time(secs): " + randTime + "\n"
  24. );