Convert more benchmark to benny
[benchmarks-js.git] / promise-handling.js
index e4e712b2f664e25e736d91d35d3876bb022f969d..002be6d429392264772e61aff6f617bebee0c277 100644 (file)
@@ -1,13 +1,12 @@
-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()
+  })
 }
 
 /**
@@ -17,21 +16,29 @@ async function asyncFunction () {
   await promise()
 }
 
-suite
-  .add('await promise', async () => {
+Benchmark.suite(
+  'Promise handling',
+  Benchmark.add('await promise', async () => {
     await asyncFunction()
-  })
-  .add('promise', () => {
+  }),
+  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', 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()
+)