Make Math.random faster

RESOLVED FIXED in mozilla43

Status

()

RESOLVED FIXED
8 years ago
3 years ago

People

(Reporter: dmandelin, Unassigned)

Tracking

Trunk
mozilla43
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

8 years ago
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.
Blocks: 773859
No longer blocks: 773859
Depends on: 773859

Comment 2

6 years ago
This should depend on Bug 774364 or be closed.
Depends on: 774364
(Assignee)

Updated

4 years ago
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)

Updated

3 years ago
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla43
You need to log in before you can comment on or make changes to this bug.