X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=quick-select.js;h=d45a9e8b4bf653c38142ebabf026cd59ef0adc44;hb=9db6379f83a78902f85f14d7cc672e8bdb7b4968;hp=502673530c3f84ca59af562e2d584e0c8e2ef32f;hpb=7fd91296ddf293e0ef084408618f4cc1f551de92;p=benchmarks-js.git diff --git a/quick-select.js b/quick-select.js index 5026735..d45a9e8 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 @@ -65,7 +63,7 @@ const defaultPivotIndexSelect = (leftIndex, rightIndex) => { } const randomPivotIndexSelect = (leftIndex, rightIndex) => { - return generateRandomInteger(leftIndex, rightIndex) + return generateRandomInteger(rightIndex, leftIndex) } /** @@ -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() +)