Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚗️ Add more libraries to the experiment #546

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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