-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark-to-site.js
42 lines (40 loc) · 1.28 KB
/
benchmark-to-site.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
#!/usr/bin/env node
const fs = require(`fs`)
/* eslint-disable */
fs.readFile(`./benchmark.log`, `utf8`, (e, data) => {
if (e) {
throw e
}
const byOpsPerSecond = (x, y) => x[1] >= y[1] ? -1 : 1
const stripCommasAndParseInt = (y) => parseInt(y.replace(/,/g, ``))
const stripEndsAndParseFloat = (z) => parseFloat(z.substr(1, z.length - 1))
const stripWordsAndMakeItGood = (a) => parseInt(a.substr(0, a.length - ` runs sampled)`.length))
const datum = data.split(`\n`)
.filter((x) => x.indexOf(`±`) > -1)
.map((x) => x
.split(`x `)
.map((y) => y.trim())
)
.map(([x, y]) => [x, ...y.split(` ops/sec `)])
.map(([x, y, z]) => [x, stripCommasAndParseInt(y), ...z.split(` (`)])
.map(([x, y, z, a]) => [
x,
y,
stripEndsAndParseFloat(z),
stripWordsAndMakeItGood(a)
])
.sort(byOpsPerSecond)
const place = `${__dirname}/website/static/generated-benchmark.js`
console.log(datum)
if (process.env.write) {
const content = `// this file was automatically created by katsu-curry/benchmark-to-site.js
module.exports = ${JSON.stringify(datum, null, 2).replace(/"/g, `\``)}
`
fs.writeFile(place, content, `utf8`, (e) => {
if (e) throw e
console.log(`wrote file to ${place}`)
})
return
}
})
/* eslint-enable */