-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbench
executable file
·73 lines (62 loc) · 1.98 KB
/
bench
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
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env node
const fs = require('fs')
const os = require('os')
const { fork, spawn } = require('child_process')
const File = require('./_internal/File')
const findAllFilePaths = require('./_internal/findAllFilePaths')
const package = require('./package.json')
const ramdaPackage = require('./node_modules/ramda/package.json')
const lodashPackage = require('./node_modules/lodash/package.json')
const asyncPackage = require('./node_modules/async/package.json')
// sortBenchmarkFilePaths(paths Array<string>) -> sorted Array<string>
const sortBenchmarkFilePaths = function (paths) {
const miscPaths = paths.filter(p => p.includes('/misc/'))
const corePaths = paths.filter(p => !p.includes('/misc/'))
corePaths.sort()
miscPaths.sort()
return corePaths.concat(miscPaths)
}
const outputFile = new File(`${__dirname}/benchmark-output/v${package.version}`)
const write = function (str) {
process.stdout.write(str)
outputFile.write(str)
}
// bench(options?: { bestOf?: number }) -> Promise<>
const bench = async function (options = {}) {
const systemInfo = [
`OS ${os.release()}`,
`NodeJS ${process.version}`,
`rubico v${package.version}`,
`ramda v${ramdaPackage.version}`,
`lodash/fp v${lodashPackage.version}`,
`async v${asyncPackage.version}`,
].join('\n')
write(systemInfo + '\n\n')
const { bestOf = 5 } = options
const paths = await
findAllFilePaths(`${__dirname}/benchmarks`)
.then(sortBenchmarkFilePaths)
const outputMap = new Map()
for (const path of paths) {
const fileName = path.replace(`${__dirname}/`, '')
write(fileName + '\n')
const lines = []
const proc = spawn('node', [path])
proc.stdout.on('data', data => {
lines.push(data.toString())
})
await new Promise(resolve => {
proc.on('close', () => {
for (const line of lines) {
write(line)
}
write('\n')
resolve()
})
})
}
}
if (process.argv[1] == __filename) {
bench()
}
module.exports = bench