forked from timotejroiko/zlib-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark-all.js
More file actions
95 lines (68 loc) · 2.3 KB
/
benchmark-all.js
File metadata and controls
95 lines (68 loc) · 2.3 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const cp = require('child_process');
const fs = require('fs');
const now = Date.now()
function buildResultsMap(results) {
const lines = results.split('\n');
const map = {}
let current = null
for (const line of lines) {
if (line.match(/^\d+\./)) {
map[line] = []
current = line
continue
}
if (line.trim() === '') {
current = null
continue
}
if (current) map[current].push(line)
}
return Object.fromEntries(Object.entries(map).map(([k, v]) => [k, v.join('\n')]))
}
function buildTable(map) {
const datas = Object.keys(map)
let res = '| | ' + datas.join(' | ') + ' |\n| --- '
let libraries = new Set()
for (const data of datas) {
res += '| --- '
for (const lib of Object.keys(map[data])) {
libraries.add(lib)
}
}
res += '|\n'
libraries = Array.from(libraries).sort((a, b) => a.split(".")[0] - b.split(".")[0])
for (const lib of libraries) {
res += `| ${lib} | `
for (const data of datas) {
const results = map[data]
if (results[lib]) {
res += `<pre>${results[lib].replace(/\n/g, '<br/>')}</pre> | `
} else {
res += ' | '
}
}
res += '\n'
}
return res
}
const args = require("minimist")(process.argv.slice(2), {
string: ["data", "kind", "tests"],
});
const dataOnly = args.data?.split(',')
const kindOnly = args.kind?.split(',') ?? fs.readdirSync(__dirname).filter(f => f.startsWith('tests_')).map(f => f.slice(6))
const testsParam = args.tests ? `--tests=${args.tests}` : ''
const all = {}
for (const kind of kindOnly) {
const res = all[kind] = {}
for (const data of fs.readdirSync('./data')) {
if (dataOnly && !dataOnly.includes(data)) continue
process.stderr.write(`Benchmarking ${kind} ${data}\n`)
const resultsDeflate = cp.execSync(`node ./benchmark.js --kind=${kind} --data=${data} ${testsParam}`, { stdio: 'pipe', encoding: 'utf-8' })
res[data] = buildResultsMap(resultsDeflate)
}
}
for (const kind of kindOnly) {
console.log('### ' + kind)
console.log(buildTable(all[kind]))
}
process.stderr.write(`Finished in ${Math.floor((Date.now() - now) / 1000)}s`)