Ignore:
Timestamp:
Feb 13, 2009, 1:18:43 AM (17 years ago)
Author:
[email protected]
Message:

Math.random is really slow on windows.

Reviewed by Jon Honeycutt.

Math.random calls WTF::randomNumber which is implemented as
the secure rand_s on windows. Unfortunately rand_s is an order
of magnitude slower than arc4random. For this reason I've
added "weakRandomNumber" for use by JavaScript's Math Object.
In the long term we should look at using our own secure PRNG
in place of the system, but this will do for now.

30% win on SunSpider on Windows, resolving most of the remaining
disparity vs. Mac.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/RandomNumberSeed.h

    r39558 r40968  
    5858}
    5959
     60inline void initializeWeakRandomNumberGenerator()
     61{
     62#if COMPILER(MSVC) && defined(_CRT_RAND_S)
     63    // We need to initialise windows rand() explicitly for Math.random
     64    unsigned seed = 0;
     65    rand_s(&seed);
     66    srand(seed);
     67#endif
     68}
    6069}
    6170
Note: See TracChangeset for help on using the changeset viewer.