-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark.js
54 lines (50 loc) · 1.64 KB
/
benchmark.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
const humanize = require('tiny-human-time')
const fs = require('fs')
const { compile, run, runScript } = require('./src/index')
const osScript = fs.readFileSync('examples/os.sh', 'utf8')
const macAddressScript = fs.readFileSync('examples/mac-addresses.sh', 'utf8')
const appInfoScript = fs.readFileSync('examples/appinfo.sh', 'utf8')
const compiledOsScript = compile(osScript)
const compiledMacAddressScript = compile(macAddressScript)
const compiledAppInfoScript = compile(appInfoScript)
// add tests
suite.add('compile (os.sh)', function() {
compile(osScript)
})
// .add('run (os.sh)', async function() {
// await run(compiledOsScript)
// })
.add('runScript (os.sh)', async function() {
await runScript(osScript)
})
// .add('compile (mac-addresses.sh)', function() {
// compile(macAddressScript)
// })
// .add('run (mac-addresses.sh)', async function() {
// await run(compiledMacAddressScript)
// })
.add('runScript (mac-addresses.sh)', async function() {
await runScript(macAddressScript)
})
// .add('compile (appinfo.sh)', function() {
// compile(appInfoScript)
// })
// .add('run (appinfo.sh)', async function() {
// await run(compiledAppInfoScript)
// })
.add('runScript (appinfo.sh)', async function() {
await runScript(appInfoScript)
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
console.log(` mean time: ${humanize.short(event.target.stats.mean*1000)}`)
// console.log("event:", event)
})
.on('complete', function() {
// console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({ 'async': true });