Skip to content

Commit

Permalink
⚗️ Add more libraries to the experiment (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz authored Mar 7, 2023
1 parent ac8b85d commit b3dfea5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/compare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ jobs:
- name: Install dependencies
run: yarn install --immutable
- name: Install extra libraries
run: yarn add chance@1.1.10 @faker-js/faker@7.6.0 random-js@2.1.0 --exact --dev
run: yarn add chance@1.1.10 @faker-js/faker@7.6.0 random-js@2.1.0 seedrandom@3.0.5 --exact --dev
- name: Build package
run: yarn build:prod
- name: Env Info
run: npx envinfo
- name: Benchmark
run: node perf/compare.cjs
51 changes: 44 additions & 7 deletions perf/compare.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const prand = require('../lib/pure-rand');
const Chance = require('chance');
const { faker } = require('@faker-js/faker');
const { Random, MersenneTwister19937 } = require('random-js');
var seedrandom = require('seedrandom');

// Algorithms under tests
function fisherYates(data, rand) {
Expand Down Expand Up @@ -113,6 +114,48 @@ async function run() {
};
fisherYates(data, rand);
});
bench.add('seedrandom (alea)', () => {
const random = seedrandom.alea(String(seed));
const rand = (min, max) => {
return min + Math.floor(random() * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('seedrandom (xor128)', () => {
const random = seedrandom.xor128(String(seed));
const rand = (min, max) => {
return min + Math.floor(random() * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('seedrandom (tychei)', () => {
const random = seedrandom.tychei(String(seed));
const rand = (min, max) => {
return min + Math.floor(random() * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('seedrandom (xorwow)', () => {
const random = seedrandom.xorwow(String(seed));
const rand = (min, max) => {
return min + Math.floor(random() * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('seedrandom (xor4096)', () => {
const random = seedrandom.xor4096(String(seed));
const rand = (min, max) => {
return min + Math.floor(random() * (max - min + 1));
};
fisherYates(data, rand);
});
bench.add('seedrandom (xorshift7)', () => {
const random = seedrandom.xorshift7(String(seed));
const rand = (min, max) => {
return min + Math.floor(random() * (max - min + 1));
};
fisherYates(data, rand);
});

// Run the benchmark
await bench.warmup();
Expand All @@ -121,13 +164,7 @@ async function run() {
// Log the results
console.table(
bench.tasks.map(({ name, result }) => {
return {
Library: name,
Mean: result?.mean,
P75: result?.p75,
P99: result?.p99,
RME: result?.rme,
};
return { Library: name, Mean: result?.mean };
})
);
}
Expand Down

0 comments on commit b3dfea5

Please sign in to comment.