jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
They are not the same. Crypto.getRandomValues
generates crypto-safe random numbers. While Math.random
is not crypto-safe AT ALL.
But how do they differ in speed?
function crypto_rand(num) {
const arr = new Uint32Array(num * 2)
self.crypto.getRandomValues(arr)
return arr
}
function math_rand(num) {
const arr = new ArrayBuffer(8 * num)
const view = new DataView(arr)
for (let i = 0; i < num; i++) {
const val = Math.random()
view.setFloat64(8 * i, val)
}
return new Uint32Array(arr);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Uint32*2 with Crypto |
| ready |
Uint32*2 with Math |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.