From e2bfb54955f0d0138b5c83a918c96112a5710d52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 24 Oct 2022 13:09:32 +0200 Subject: [PATCH] Switch more benchmarks to benny MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- empty-array.js | 4 +-- promise-handling.js | 6 ++-- quick-select.js | 68 ++++++++++++++++++++++----------------------- random.js | 4 +-- 4 files changed, 40 insertions(+), 42 deletions(-) diff --git a/empty-array.js b/empty-array.js index 0c5f725..52f836e 100644 --- a/empty-array.js +++ b/empty-array.js @@ -8,12 +8,12 @@ Benchmark.suite( Benchmark.add('length = 0', () => { testArray.length = 0 }), - Benchmark.add('pop loop', async () => { + Benchmark.add('pop loop', () => { while (testArray.length > 0) { testArray.pop() } }), - Benchmark.add('splice', async () => { + Benchmark.add('splice', () => { testArray.splice(0, testArray.length) }), Benchmark.add('shift loop', () => { diff --git a/promise-handling.js b/promise-handling.js index bed3ac4..e4e712b 100644 --- a/promise-handling.js +++ b/promise-handling.js @@ -18,13 +18,13 @@ async function asyncFunction () { } suite - .add('await promise', async function () { + .add('await promise', async () => { await asyncFunction() }) - .add('promise', function () { + .add('promise', () => { asyncFunction() }) - .on('cycle', function (event) { + .on('cycle', event => { console.log(event.target.toString()) }) .on('complete', function () { diff --git a/quick-select.js b/quick-select.js index 5026735..4be2205 100644 --- a/quick-select.js +++ b/quick-select.js @@ -1,7 +1,5 @@ -const Benchmark = require('benchmark') -const { generateRandomInteger, LIST_FORMATTER } = require('./benchmark-utils') - -const suite = new Benchmark.Suite() +const Benchmark = require('benny') +const { generateRandomInteger } = require('./benchmark-utils') /** * @param numberOfWorkers @@ -229,41 +227,41 @@ function quickSelectRecursionRandomPivot (tasksMap) { ) } -// console.log(Array.from(tasksMap)) -// console.log(loopSelect(tasksMap)) -// console.log(arraySortSelect(tasksMap)) -// console.log(quickSelectLoop(tasksMap)) -// console.log(quickSelectLoopRandomPivot(tasksMap)) -// console.log(quickSelectRecursion(tasksMap)) -// console.log(quickSelectRecursionRandomPivot(tasksMap)) - -suite - .add('Loop select', function () { +Benchmark.suite( + 'Quick select', + Benchmark.add('Loop select', () => { loopSelect(tasksMap) - }) - .add('Array sort select', function () { + }), + Benchmark.add('Array sort select', () => { arraySortSelect(tasksMap) - }) - .add('Quick select loop', function () { + }), + Benchmark.add('Quick select loop', () => { quickSelectLoop(tasksMap) - }) - .add('Quick select loop with random pivot', function () { + }), + Benchmark.add('Quick select loop with random pivot', () => { quickSelectLoopRandomPivot(tasksMap) - }) - .add('Quick select recursion', function () { + }), + Benchmark.add('Quick select recursion', () => { quickSelectRecursion(tasksMap) - }) - .add('Quick select recursion with random pivot', function () { + }), + Benchmark.add('Quick select recursion with random pivot', () => { quickSelectRecursionRandomPivot(tasksMap) + }), + Benchmark.cycle(), + Benchmark.complete(), + Benchmark.save({ + file: 'quick-select', + format: 'json', + details: true + }), + Benchmark.save({ + file: 'quick-select', + format: 'chart.html', + details: true + }), + Benchmark.save({ + file: 'quick-select', + format: 'table.html', + details: true }) - .on('cycle', function (event) { - console.log(event.target.toString()) - }) - .on('complete', function () { - console.log( - 'Fastest is ' + LIST_FORMATTER.format(this.filter('fastest').map('name')) - ) - // eslint-disable-next-line n/no-process-exit - process.exit() - }) - .run() +) diff --git a/random.js b/random.js index 1eeeedd..ed5acd6 100644 --- a/random.js +++ b/random.js @@ -33,10 +33,10 @@ function getRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) { Benchmark.suite( 'Random Integer Generator', - Benchmark.add('Secure random integer generator', function () { + Benchmark.add('Secure random integer generator', () => { getSecureRandomInteger(maximum) }), - Benchmark.add('Random integer generator', function () { + Benchmark.add('Random integer generator', () => { getRandomInteger(maximum) }), Benchmark.cycle(), -- 2.34.1