Skip to content

Commit

Permalink
⚗️ Add some more non-uniform versions (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Mar 1, 2023
1 parent 44af2ad commit ac8b85d
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion perf/compare.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,38 @@ async function run() {
};
fisherYates(data, rand);
});
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));
};
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));
};
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));
};
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));
};
fisherYates(data, rand);
});
bench.add('pure-rand (xorshift128plus)', () => {
const g = prand.xorshift128plus(seed);
const rand = (min, max) => {
Expand Down Expand Up @@ -61,13 +93,14 @@ async function run() {
fisherYates(data, rand);
});
bench.add('chance', () => {
const chance = new Chance();
const chance = new Chance(seed);
const rand = (min, max) => {
return chance.integer({ min, max });
};
fisherYates(data, rand);
});
bench.add('faker', () => {
faker.seed(seed);
const rand = (min, max) => {
return faker.datatype.number({ min, max });
};
Expand Down

0 comments on commit ac8b85d

Please sign in to comment.