-
-
Notifications
You must be signed in to change notification settings - Fork 232
/
bench.js
60 lines (52 loc) · 1.39 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
import { access } from 'node:fs/promises'
import { fork } from 'child_process'
import ora from 'ora'
import { join } from 'path'
import { fire } from './autocannon.js'
import { fileURLToPath } from 'url'
import assert from 'assert'
const __dirname = fileURLToPath(new URL('.', import.meta.url))
const doBench = async (opts, handler) => {
const spinner = ora(`Started ${handler}`).start()
let forked
try {
await access(join(__dirname, '..', 'benchmarks', handler + '.cjs'))
forked = fork(join(__dirname, '..', 'benchmarks', handler + '.cjs'))
} catch {
forked = fork(join(__dirname, '..', 'benchmarks', handler + '.mjs'))
}
try {
spinner.color = 'magenta'
spinner.text = `Warming ${handler}`
await fire(opts, handler, false)
} catch (error) {
return console.log(error)
} finally {
spinner.color = 'yellow'
spinner.text = `Working ${handler}`
}
try {
await fire(opts, handler, true)
assert.ok(forked.kill('SIGINT'))
spinner.text = `Results saved for ${handler}`
spinner.succeed()
return true
} catch (error) {
return console.log(error)
}
}
let index = 0
const start = async (opts, list) => {
if (list.length === index) {
return true
}
try {
await doBench(opts, list[index])
index += 1
return start(opts, list)
} catch (error) {
return console.log(error)
}
}
export default start