X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=empty-array.js;h=a56a82461f8ef272cf0210df5e81abd069ae8cc6;hb=608f28eb3564ee54788d8f3ac20fd815046e5c73;hp=9f93d3267ae33b089d661b7b11ecba06e5a8b4c3;hpb=2deff321e347e2ca6c419c5d98b82fe2f5595a03;p=benchmarks-js.git diff --git a/empty-array.js b/empty-array.js index 9f93d32..a56a824 100644 --- a/empty-array.js +++ b/empty-array.js @@ -1,51 +1,33 @@ -const Benchmark = require('benchmark') -const { LIST_FORMATTER } = require('./benchmark-utils') +const Benchmark = require('benny') +const { generateRandomNumberArray } = require('./benchmark-utils') -const suite = new Benchmark.Suite() +const size = 10000 +let testArray = generateRandomNumberArray(size) -let testArray = [ - 83, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, - 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, - 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, - 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, - 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, - 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, 56, 32, - 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, 234, 23, - 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, 29, 2828, - 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, 93, 27, - 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, 36, 28, - 93, 27, 29, 2828, 234, 23, 56, 32, 56, 67, 77, 32, 45, 93, 17, 28, 83, 62, 99, - 36, 28 -] - -suite - .add('length = 0', () => { +Benchmark.suite( + `Empty array with ${size} elements`, + Benchmark.add('length = 0', () => { testArray.length = 0 - }) - .add('pop loop', async () => { + }), + Benchmark.add('pop loop', () => { while (testArray.length > 0) { testArray.pop() } - }) - .add('splice', async () => { + }), + Benchmark.add('splice', () => { testArray.splice(0, testArray.length) - }) - .add('shift loop', () => { + }), + Benchmark.add('shift loop', () => { while (testArray.length > 0) { testArray.shift() } - }) - .add('new init', () => { + }), + Benchmark.add('new init', () => { testArray = [] - }) - .on('cycle', 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() + }), + Benchmark.cycle(), + Benchmark.complete(), + Benchmark.save({ file: 'empty-array', format: 'json', details: true }), + Benchmark.save({ file: 'empty-array', format: 'chart.html', details: true }), + Benchmark.save({ file: 'empty-array', format: 'table.html', details: true }) +)