diff --git a/.github/workflows/compare.yml b/.github/workflows/compare.yml index 59f7436a..17fbf2e2 100644 --- a/.github/workflows/compare.yml +++ b/.github/workflows/compare.yml @@ -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 diff --git a/perf/compare.cjs b/perf/compare.cjs index 20085bfc..3f425973 100644 --- a/perf/compare.cjs +++ b/perf/compare.cjs @@ -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) { @@ -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(); @@ -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 }; }) ); }