Skip to content

Commit 147c9c5

Browse files
committed
Add V8 benchmarks
Thanks @gengjiawen for the base runner script!
1 parent dcdc2b1 commit 147c9c5

File tree

3 files changed

+16382
-0
lines changed

3 files changed

+16382
-0
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ Eg:
4646
```bash
4747
./build/run_octane
4848
```
49+
50+
### V8
51+
52+
For the V8 benchmarks Node is used as the runner:
53+
54+
```bash
55+
cd v8
56+
node benchmark.js "QuickJS (master)" ../../quickjs/build/qjs-master "QuickJS (this PR)" ../../quickjs/build/qjs "V8 (jitless)" "v8 --jitless"
57+
```
58+
59+
The script takes pairs of "name" and "command" and generates a Markdown table at the end.

v8/benchmark.js

+149
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
const { exec } = require('child_process')
2+
const fs = require('fs')
3+
const process = require('process');
4+
5+
6+
function parseResults(output) {
7+
const jsonString = output.match(/\[.*\]/)
8+
return jsonString ? JSON.parse(jsonString[0]) : []
9+
}
10+
11+
function createMarkdownTable(results, commandNames) {
12+
const benchmarks = new Set()
13+
14+
commandNames.forEach((name) => {
15+
results[name].forEach((entry) => {
16+
benchmarks.add(entry.name)
17+
})
18+
})
19+
20+
const benchmarkArray = Array.from(benchmarks)
21+
const columnWidths = [Math.max(...benchmarkArray.map((b) => b.length), 37)]
22+
23+
commandNames.forEach((name) => {
24+
const maxLength = Math.max(
25+
...results[name].map((entry) => entry.result.toString().length),
26+
name.length,
27+
17
28+
)
29+
columnWidths.push(maxLength)
30+
})
31+
32+
let table = '| Benchmark (Higher scores are better) '
33+
commandNames.forEach((name, index) => {
34+
table += `| ${name.padEnd(columnWidths[index + 1])} `
35+
})
36+
table += '|\n'
37+
38+
table += '|-' + '-'.repeat(columnWidths[0]) + '-'
39+
commandNames.forEach((_, index) => {
40+
table += '|-' + '-'.repeat(columnWidths[index + 1]) + '-'
41+
})
42+
table += '|\n'
43+
44+
benchmarkArray.forEach((benchmark) => {
45+
const row = [`| ${benchmark.padEnd(columnWidths[0])}`]
46+
commandNames.forEach((name, index) => {
47+
const result = results[name].find((entry) => entry.name === benchmark)
48+
row.push(
49+
`| ${
50+
result
51+
? result.result.toString().padEnd(columnWidths[index + 1])
52+
: 'N/A'.padEnd(columnWidths[index + 1])
53+
}`
54+
)
55+
})
56+
table += `${row.join(' ')} |\n`
57+
})
58+
59+
return table
60+
}
61+
62+
function createCSV(results, commandNames) {
63+
let csv = 'Benchmark,'
64+
csv += commandNames.join(',') + '\n'
65+
66+
const benchmarks = new Set()
67+
68+
commandNames.forEach((name) => {
69+
results[name].forEach((entry) => {
70+
benchmarks.add(entry.name)
71+
})
72+
})
73+
74+
benchmarks.forEach((benchmark) => {
75+
const row = [benchmark]
76+
commandNames.forEach((name) => {
77+
const result = results[name].find((entry) => entry.name === benchmark)
78+
row.push(result ? result.result.toString() : 'N/A')
79+
})
80+
csv += `${row.join(',')}\n`
81+
})
82+
83+
return csv
84+
}
85+
86+
const commands = [
87+
//{ name: 'V8 --jitless', command: 'v8 --jitless },
88+
//{ name: 'V8', command: 'v8' },
89+
//{ name: 'JSC', command: 'jsc' },
90+
// Add more engines here
91+
]
92+
93+
const results = {}
94+
95+
function main() {
96+
commands.forEach(({ name, command }, index) => {
97+
console.log(`Running ${name}: ${command}`)
98+
exec(command, (error, stdout, stderr) => {
99+
if (error) {
100+
console.error(`Error executing ${name}: ${error.message}`)
101+
return
102+
}
103+
104+
const r = parseResults(stdout)
105+
console.log(name, r)
106+
results[name] = r
107+
108+
if (Object.keys(results).length === commands.length) {
109+
const markdownTable = createMarkdownTable(
110+
results,
111+
commands.map((cmd) => cmd.name)
112+
)
113+
console.log('Markdown Table:')
114+
console.log(markdownTable)
115+
116+
/*
117+
const csvContent = createCSV(
118+
results,
119+
commands.map((cmd) => cmd.name)
120+
)
121+
122+
fs.writeFileSync('benchmark_results.csv', csvContent)
123+
console.log('CSV file has been saved as benchmark_results.csv')
124+
*/
125+
}
126+
})
127+
})
128+
}
129+
130+
let args = process.argv.slice(2)
131+
132+
for (;;) {
133+
const [ name, cmd, ...rest ] = args
134+
135+
if (!name || !cmd)
136+
break
137+
138+
commands.push({
139+
name,
140+
command: `${cmd} combined.js`
141+
})
142+
143+
if (!rest.length)
144+
break
145+
146+
args = rest
147+
}
148+
149+
main()

0 commit comments

Comments
 (0)