davidbau / seedrandom

seeded random number generator for Javascript
2.04k stars 160 forks source link

asm.js #24

Open jeffrose opened 9 years ago

jeffrose commented 9 years ago

Have you looked into using asm.js for the PRNG algorithms?

http://asmjs.org/

It may take a little refactoring but there is a potential speed boost.

http://jsperf.com/asm-js-rng/6

davidbau commented 9 years ago

Unfortunately, "jsperf is temporarily unavailable" is what we've been getting for a while, and I haven't been able to see the code that you created. Can you write what you had in mind in this issue?

I had been reluctant to depend on typed arrays (for old browser compatibility) but perhaps it's time to start using them if there is a significant speed benefit. I'd be open to patches with benchmarks.

jeffrose commented 9 years ago

It wasn't my jsperf but it showed a comparison of the same algorithm implemented in both asm.js and plain JavaScript. The asm.js version performed better.

It looks like using typed arrays would only exclude IE8 and IE9 unless a Uint8ClampedArrayis used then IE10 would be excluded as well.

http://caniuse.com/#feat=typedarrays

So it's a matter of how important is IE8-9 support to you. If someone needs support for those browser, they could always load a polyfill beforehand.

Typed arrays aside, the use of asm.js would be ignored by browsers that don't support it. That is, the code would just execute like regular JavaScript.

Personally I've never used asm.js in my own development, but it seems like crypto is a decent use case for it.

CoDEmanX commented 8 years ago

JSPerf seems to work (again), and if I read the results correctly, asm.js outperforms normal JS by factor 10 in Firefox.

jeffrose commented 8 years ago

It is a pretty significant performance difference.

screen shot 2016-01-14 at 10 55 06 am screen shot 2016-01-14 at 11 03 44 am