-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
index.js
37 lines (32 loc) · 1.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const { readdirSync } = require('fs')
const { basename, extname, resolve } = require('path')
const { resetMemoization } = require('slate')
const { Suite, Bench } = require('slate-dev-benchmark')
/**
* Benchmarks.
*/
module.exports.run = function(include) {
const categoryDir = resolve(__dirname)
const categories = readdirSync(categoryDir).filter(
c => c[0] !== '.' && c !== 'index.js'
)
categories.forEach(category => {
const suite = new Suite(category, { minTries: 100, minTime: 1000 })
const benchmarkDir = resolve(categoryDir, category)
const benchmarks = readdirSync(benchmarkDir)
.filter(b => b[0] !== '.' && !!~b.indexOf('.js'))
.map(b => basename(b, extname(b)))
benchmarks.forEach(benchmark => {
if (include && !benchmark.match(include)) return
const bench = new Bench(suite, benchmark)
const dir = resolve(benchmarkDir, benchmark)
const module = require(dir)
const fn = module.default
bench.input(() => module.input)
bench.run(input => {
fn(input)
resetMemoization()
})
})
})
}