feat(scripts): benchmarks (#2631)
This commit is contained in:
51
scripts/benchmarks
Executable file
51
scripts/benchmarks
Executable 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)
|
||||
})
|
||||
Reference in New Issue
Block a user