Skip to content

Commit

Permalink
⚗️ Rewrite not uniform of pure-rand (#547)
Browse files Browse the repository at this point in the history
Just rewritting the non-uniform distribution used into our benchmark as the implementation provided for pure-rand looked laggy compared to the ones provided on others.
  • Loading branch information
dubzzz authored Mar 7, 2023
1 parent 405507b commit 556ec33
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions perf/compare.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,32 @@ async function run() {
bench.add('pure-rand (xorshift128plus) (not uniform)', () => {
const g = prand.xorshift128plus(seed);
const rand = (min, max) => {
const out = g.unsafeNext() >>> 0;
return min + (out % (max - min + 1));
const out = (g.unsafeNext() >>> 0) / 0x1_0000_0000;
return min + Math.floor(out * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('pure-rand (xoroshiro128plus) (not uniform)', () => {
const g = prand.xoroshiro128plus(seed);
const rand = (min, max) => {
const out = g.unsafeNext() >>> 0;
return min + (out % (max - min + 1));
const out = (g.unsafeNext() >>> 0) / 0x1_0000_0000;
return min + Math.floor(out * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('pure-rand (mersenne) (not uniform)', () => {
const g = prand.mersenne(seed);
const rand = (min, max) => {
const out = g.unsafeNext() >>> 0;
return min + (out % (max - min + 1));
const out = (g.unsafeNext() >>> 0) / 0x1_0000_0000;
return min + Math.floor(out * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('pure-rand (congruential32) (not uniform)', () => {
const g = prand.congruential32(seed);
const rand = (min, max) => {
const out = g.unsafeNext() >>> 0;
return min + (out % (max - min + 1));
const out = (g.unsafeNext() >>> 0) / 0x1_0000_0000;
return min + Math.floor(out * (max - min + 1));
};
fisherYates(data, rand);
});
Expand Down

0 comments on commit 556ec33

Please sign in to comment.