Closed Bug 587255 Opened 14 years ago Closed 9 years ago

Make Math.random faster

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla43

People

(Reporter: dmandelin, Unassigned)

References

Details

We are currently 2x slower than JSC on this microbenchmark:

  function f() {
    for (var i = 0; i < 10000000; ++i) {
      Math.random(1);
    }
  }

  var t0 = new Date;
  f();
  print(new Date - t0);

I did the comparison again with the body of Math.random mostly commented out on both sides, and it seems we are about the same speed then. So, the difference is probably in the RNG itself.

JM wanted SS win: 2 ms
Interp: 1470
TM: 1476
JM: 606
JM+TI: 582
d8: 249

About 2x slower than v8. I don't have a JSC shell available to test against.
No longer blocks: 773859
Depends on: 773859
This should depend on Bug 774364 or be closed.
Depends on: 774364
Assignee: general → nobody
I'm guessing this might as well be closed?
Flags: needinfo?(arai.unmht)
Tested with modified code.

code:
  var n = 0;
  function f() {
    for (var i = 0; i < 100000000; ++i) {
      n += Math.random();  // use return value, to avoid getting optimized away
    }
  }
  var t0 = new Date;
  f();
  console.log(new Date - t0);

results:

x86_64
  Firefox 40      : 790
  Firefox Nightly : 450
  Chrome          : 1122 (4404 on 2nd run, not sure why...)
  Chrome Canary   : 1494 (5397)
  Safari          : 1366
  WebKit          : 963

x86
  Firefox 40      : 1549
  Firefox Nightly : 782

I think it's fast enough :)
Flags: needinfo?(arai.unmht)
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
You need to log in before you can comment on or make changes to this bug.