X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=promise-handling.js;h=b07b33d835583ae15f6edf8fd26b6cbc437953eb;hb=43a6273cfba404cda3b7e809f4f3074af3808f68;hp=182ba772bef44b6c60ced6f74e6e1d79a15920ec;hpb=ed2968f2ee816cb47841f537bcbfb8590aa7bbb9;p=benchmarks-js.git diff --git a/promise-handling.js b/promise-handling.js index 182ba77..b07b33d 100644 --- a/promise-handling.js +++ b/promise-handling.js @@ -1,31 +1,44 @@ -const Benchmark = require('benchmark') -const { LIST_FORMATTER } = require('./benchmark-utils') - -const suite = new Benchmark.Suite() +const Benchmark = require('benny') +/** + * + */ function promise () { - return new Promise() + return new Promise(resolve => { + resolve() + }) } +/** + * + */ async function asyncFunction () { - await promise() + return await promise() } -suite - .add('await promise', async function () { +Benchmark.suite( + 'Promise handling', + Benchmark.add('await promise', async () => { await asyncFunction() - }) - .add('promise', function () { + }), + Benchmark.add('promise', () => { asyncFunction() + }), + Benchmark.cycle(), + Benchmark.complete(), + Benchmark.save({ + file: 'promise-handling', + format: 'json', + details: true + }), + Benchmark.save({ + file: 'promise-handling', + format: 'chart.html', + details: true + }), + Benchmark.save({ + file: 'promise-handling', + 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 no-process-exit - process.exit() - }) - .run() +)