X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fworker-selection%2Fleast.mjs;h=ca5de3c1821de7bed57680fe1a3acd4aae3e398a;hb=ecde6ea8c439bbdd9dc2ca118731b5006a1a9884;hp=6dd91df0e1e0e436c4921748c0e622c6c020147d;hpb=d35e571704515a8b729d3455e4784054f07c368f;p=poolifier.git diff --git a/benchmarks/worker-selection/least.mjs b/benchmarks/worker-selection/least.mjs index 6dd91df0..ca5de3c1 100644 --- a/benchmarks/worker-selection/least.mjs +++ b/benchmarks/worker-selection/least.mjs @@ -1,5 +1,6 @@ -import Benchmark from 'benchmark' -import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.cjs' +import { randomInt } from 'node:crypto' + +import { bench, group, run } from 'tatami-ng' function generateRandomTasksMap ( numberOfWorkers, @@ -7,7 +8,7 @@ function generateRandomTasksMap ( ) { const tasksArray = [] for (let i = 0; i < numberOfWorkers; i++) { - const task = [i, generateRandomInteger(maxNumberOfTasksPerWorker)] + const task = [i, randomInt(maxNumberOfTasksPerWorker)] tasksArray.push(task) } return new Map(tasksArray) @@ -50,7 +51,7 @@ const defaultPivotIndexSelect = (leftIndex, rightIndex) => { } const randomPivotIndexSelect = (leftIndex, rightIndex) => { - return generateRandomInteger(rightIndex, leftIndex) + return randomInt(leftIndex, rightIndex) } function swap (array, index1, index2) { @@ -167,31 +168,25 @@ function quickSelectRecursionRandomPivot (tasksMap) { ) } -new Benchmark.Suite('Least used worker tasks distribution') - .add('Loop select', () => { +group('Least used worker tasks distribution', () => { + bench('Loop select', () => { loopSelect(tasksMap) }) - .add('Array sort select', () => { + bench('Array sort select', () => { arraySortSelect(tasksMap) }) - .add('Quick select loop', () => { + bench('Quick select loop', () => { quickSelectLoop(tasksMap) }) - .add('Quick select loop with random pivot', () => { + bench('Quick select loop with random pivot', () => { quickSelectLoopRandomPivot(tasksMap) }) - .add('Quick select recursion', () => { + bench('Quick select recursion', () => { quickSelectRecursion(tasksMap) }) - .add('Quick select recursion with random pivot', () => { + bench('Quick select recursion with random pivot', () => { quickSelectRecursionRandomPivot(tasksMap) }) - .on('cycle', event => { - console.info(event.target.toString()) - }) - .on('complete', function () { - console.info( - 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) - ) - }) - .run() +}) + +await run({ units: true })