-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbench.js
36 lines (31 loc) · 1.23 KB
/
bench.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
const { run } = require('@run')
const { ANSI } = require('@binary')
const stats = require('stats.js')
const fs = require('fs')
const { writeFile } = fs
async function launch () {
if (just.opts.flush) {
writeFile('/proc/sys/vm/drop_caches', ArrayBuffer.fromString('3'))
await run('sync').waitfor()
}
const program = await run('./smol').waitfor()
if (program.status !== 0) throw new just.SystemError(`exec status ${status}`)
return Number(program.out)
}
const times = []
const { eraseLine, column } = ANSI.control
const runs = parseInt(just.args[2] || '100', 10)
for (let i = 0; i < runs; i++) {
const t = await launch()
just.print(`${column(0)}${eraseLine()}${(i + 1).toString().padEnd(10, ' ')} : ${t}`, false)
times.push(t)
}
just.print('')
just.print(`mean ${parseInt(stats.mean(times), 10)} nsec`)
just.print(`median ${parseInt(stats.median(times), 10)} nsec`)
just.print(`stdDev ${parseInt(stats.standardDeviation(times), 10)} nsec`)
just.print(`max ${stats.max(times)} nsec`)
just.print(`min ${stats.min(times)} nsec`)
just.print(`range ${stats.range(times)} nsec`)
just.print(`midrange ${stats.midrange(times)} nsec`)
just.print(`absDev ${parseInt(stats.meanAbsoluteDeviation(times), 10)} nsec`)