feat(scripts): benchmarks (#2631)

This commit is contained in:
Julien Fontanet
2018-02-09 15:01:00 +01:00
committed by GitHub
parent 9fc73e03a2
commit a0cc768af9
4 changed files with 58 additions and 11 deletions

51
scripts/benchmarks Executable file
View File

@@ -0,0 +1,51 @@
#!/usr/bin/env node
require('@babel/register')
const pkg = require('../package.json')
const Benchmark = require('benchmark')
const globby = require('globby')
const resolve = require('path').resolve
// ===================================================================
function bench (path) {
let fn = require(resolve(path))
if (typeof fn !== 'function') {
fn = fn.default
}
const benchmarks = []
function benchmark (name, fn) {
benchmarks.push(new Benchmark(name, fn))
}
fn({
benchmark: benchmark,
})
benchmarks.forEach(function (benchmark) {
console.log(String(benchmark.run()))
})
}
function main () {
return globby(
pkg.workspaces.map(workspace =>
resolve(__dirname, '..', workspace, 'src/**/*.bench.js')
)
).then(function (paths) {
if (!paths.length) {
throw new Error('no files to run')
}
for (let i = 0, n = paths.length; i < n; ++i) {
bench(paths[i])
}
})
}
new Promise(function (resolve) {
resolve(main())
}).catch(function (error) {
console.log((error != null && (error.stack || error.message)) || error)
})