Fix(bench): wrong location (#2932)

* Update commentBenchResult.yml

* ci: fix ext

* refactor(bench): better table
This commit is contained in:
Jonathan Ho
2023-04-01 23:27:54 +00:00
committed by GitHub
parent 6359972e38
commit 9c7b2b832e
5 changed files with 124 additions and 186 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ jobs:
- name: Generate Message
id: genMessage
run: |
MESSAGE=$(deno run -A performance/generateMessage.ts)
MESSAGE=$(deno run -A scripts/generateMessage.js)
echo "MESSAGE<<EOF" >> $GITHUB_ENV
echo "$MESSAGE" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
+1 -1
View File
@@ -15,7 +15,7 @@
"fmt": "eslint --fix \"src/**/*.ts*\"",
"lint": "eslint \"src/**/*.ts*\"",
"build": "swc src --delete-dir-on-start --out-dir dist && node ../../scripts/fixBenchExtension.js",
"build-message": "swc src/utils/generateMessage.ts --out-dir ../../scripts && node ../../scripts/fixBenchExtension.js",
"build-message": "swc src/generateMessage.ts -C sourceMaps=false --out-dir ../../scripts && node ../../scripts/fixBenchExtension.js",
"bench": "node dist/index.js"
},
"dependencies": {
+83
View File
@@ -0,0 +1,83 @@
import fs from 'node:fs/promises'
const benchmarkData = await fetch(`https://raw.githubusercontent.com/discordeno/discordeno/benchies/benchmarksResult/data.js`)
.then(async (res) => await res.text())
.then((text) => JSON.parse(text.slice(24)))
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
const commitSha = await fs.readFile('./sha', 'utf-8')
const results = JSON.parse(await fs.readFile('./data.json', 'utf-8'))
interface BenchmarksData {
commit: {
author: { email: string; name: string; username: string }
committer: { email: string; name: string; username: string }
distinct: boolean
id: string
message: string
timestamp: string
tree_id: string
url: string
}
date: number
tool: string
benches: Array<{ name: string; value: number; unit: string; range: string }>
}
type CompareTable = Record<string, Record<string, { name: string; value: number; unit: string; range: string }>>
const benchmarks = results.entries.Benchmark as BenchmarksData[]
benchmarks.reverse()
const compareWithHead: CompareTable = {}
const latestBaseBenchmarks = benchmarkData.entries.Benchmark.slice(-1)[0] as BenchmarksData
for (const benchmark of latestBaseBenchmarks.benches) {
compareWithHead[benchmark.name] = {
[latestBaseBenchmarks.commit.id]: benchmark,
}
}
for (let i = 0; i < benchmarks.length; i++) {
for (const bench of benchmarks[i].benches) {
if (compareWithHead[bench.name]) {
compareWithHead[bench.name][benchmarks[i].commit.id] = bench
} else {
compareWithHead[bench.name] = {
[benchmarks[i].commit.id]: bench,
}
}
}
}
let message = '<!-- benchmark comment by ci -->\n'
message += `## Benchmark\n\n`
message += '<details><summary>Detail results of benchmarks</summary>\n\n'
let header1 = `| Benchmark suite | Base (${latestBaseBenchmarks.commit.id}) |`
let header2 = `|-|-|`
for (const [index, commitId] of benchmarks.map((benchmark) => benchmark.commit.id).entries()) {
header1 += index === 0 ? ` Latest Head (${commitId}) |` : ` ${commitId} |`
header2 += '-|'
}
message += `${header1}\n`
message += `${header2}\n`
for (const benchName of Object.keys(compareWithHead)) {
let benchData = `| ${benchName} |`
benchData += compareWithHead[benchName][latestBaseBenchmarks.commit.id]
? ` ${`\`${compareWithHead[benchName][latestBaseBenchmarks.commit.id].value}\` ${
compareWithHead[benchName][latestBaseBenchmarks.commit.id].unit
} \`${compareWithHead[benchName][latestBaseBenchmarks.commit.id].range}\``} |`
: '|'
for (const commitId of benchmarks.map((benchmark) => benchmark.commit.id)) {
benchData += compareWithHead[benchName][commitId]
? ` \`${compareWithHead[benchName][commitId].value}\` ${compareWithHead[benchName][commitId].unit} \`${compareWithHead[benchName][commitId].range}\`|`
: '|'
}
message += `${benchData}\n`
}
message += '</details>\n\n'
console.log(message.replaceAll('`', '\\`'))
@@ -1,121 +0,0 @@
import fs from 'fs/promises'
const benchmarkData = await fetch(`https://raw.githubusercontent.com/discordeno/discordeno/benchies/benchmarksResult/data.js`)
.then(async (res) => await res.text())
.then((text) => JSON.parse(text.slice(24)))
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
const commitSha = await fs.readFile('./sha', 'utf-8')
const results = JSON.parse(await fs.readFile('./data.json', 'utf-8'))
interface BenchmarksData {
commit: {
author: { email: string; name: string; username: string }
committer: { email: string; name: string; username: string }
distinct: boolean
id: string
message: string
timestamp: string
tree_id: string
url: string
}
date: number
tool: string
benches: Array<{ name: string; value: number; unit: string; range: string }>
}
type CompareTable = Record<
string,
{
current:
| { name: string; value: number; unit: string; range: string }
| {
name?: string
value?: number
unit?: string
range?: string
}
previous:
| { name: string; value: number; unit: string; range: string }
| {
name?: string
value?: number
unit?: string
range?: string
}
}
>
const benchmarks = results.entries.Benchmark.slice(-2) as BenchmarksData[]
const latestHeadBenchmarks = benchmarks.length === 2 ? benchmarks[1] : benchmarks[0]
const lastHeadBenchmarks = benchmarks.length === 2 ? benchmarks[0] : undefined
const latestBaseBenchmarks = JSON.parse(JSON.stringify(benchmarkData.entries.Benchmark)).slice(-1)[0] as BenchmarksData
const compareWithHead: CompareTable = {}
const compareWithBase: CompareTable = {}
if (lastHeadBenchmarks) {
for (const benchmark of lastHeadBenchmarks.benches) {
compareWithHead[benchmark.name] = {
previous: benchmark,
current: {},
}
}
}
for (const benchmark of latestBaseBenchmarks.benches) {
compareWithBase[benchmark.name] = {
previous: benchmark,
current: {},
}
}
for (const benchmark of latestHeadBenchmarks.benches) {
compareWithBase[benchmark.name] = {
// @ts-expect-error it should work
previous: {},
...compareWithBase[benchmark.name],
current: benchmark,
}
compareWithHead[benchmark.name] = {
// @ts-expect-error it should work
previous: {},
...compareWithHead[benchmark.name],
current: benchmark,
}
}
let message = '<!-- benchmark comment by ci -->\n'
const compareTableInfo = [
{ name: 'last head', commit: lastHeadBenchmarks ? lastHeadBenchmarks.commit.id : '' },
{
name: 'base',
commit: latestBaseBenchmarks.commit.id,
},
]
for (const benchmarkType of ['Performance', 'Memory']) {
message += `# ${benchmarkType} Benchmark\n\n`
for (const [index, compare] of [compareWithHead, compareWithBase].entries()) {
message += `## Compared with ${compareTableInfo[index].name}\n`
message += '<details><summary>Detail results of benchmarks</summary>\n\n'
message += `| Benchmark suite | Current: ${latestHeadBenchmarks.commit.id} | Previous: ${compareTableInfo[index].commit} | Ratio |\n | -| -| -| -|\n`
for (const field of Object.keys(compare).filter((key) =>
benchmarkType === 'Performance' ? !key.startsWith('[Cache Plugin]') : key.startsWith('[Cache Plugin]'),
)) {
message += `| \`${field}\` | ${compare[field].current.value ? `\`${compare[field].current.value!}\`` : ''} ${
compare[field].current.unit ?? ''
} ${compare[field].current.range ? `(\`${compare[field].current.range ?? ''}\`)` : ''} | ${
compare[field].previous.value ? `\`${compare[field].previous.value!}\`` : ''
} ${compare[field].previous.unit ?? ''} ${compare[field].previous.range ? `(\`${compare[field].previous.range ?? ''}\`)` : ''} | ${
compare[field].previous.value && compare[field].current.value
? `\`${
// @ts-expect-error it work
Math.round((parseFloat(compare[field].previous.value) / parseFloat(compare[field].current.value)) * 100) / 100
}\``
: ''
} |\n`
}
message += '</details>\n\n'
}
}
console.log(message.replaceAll('`', '\\`'))
+38 -62
View File
@@ -1,78 +1,54 @@
import fs from 'fs/promises'
import fs from 'node:fs/promises'
const benchmarkData = await fetch(`https://raw.githubusercontent.com/discordeno/discordeno/benchies/benchmarksResult/data.js`)
.then(async (res) => await res.text())
.then((text) => JSON.parse(text.slice(24)))
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
const commitSha = await fs.readFile('./sha', 'utf-8')
const results = JSON.parse(await fs.readFile('./data.json', 'utf-8'))
const benchmarks = results.entries.Benchmark.slice(-2)
const latestHeadBenchmarks = benchmarks.length === 2 ? benchmarks[1] : benchmarks[0]
const lastHeadBenchmarks = benchmarks.length === 2 ? benchmarks[0] : undefined
const latestBaseBenchmarks = JSON.parse(JSON.stringify(benchmarkData.entries.Benchmark)).slice(-1)[0]
const benchmarks = results.entries.Benchmark
benchmarks.reverse()
const compareWithHead = {}
const compareWithBase = {}
if (lastHeadBenchmarks) {
for (const benchmark of lastHeadBenchmarks.benches) {
compareWithHead[benchmark.name] = {
previous: benchmark,
current: {},
}
}
}
const latestBaseBenchmarks = benchmarkData.entries.Benchmark.slice(-1)[0]
for (const benchmark of latestBaseBenchmarks.benches) {
compareWithBase[benchmark.name] = {
previous: benchmark,
current: {},
}
}
for (const benchmark of latestHeadBenchmarks.benches) {
compareWithBase[benchmark.name] = {
// @ts-expect-error it should work
previous: {},
...compareWithBase[benchmark.name],
current: benchmark,
}
compareWithHead[benchmark.name] = {
// @ts-expect-error it should work
previous: {},
...compareWithHead[benchmark.name],
current: benchmark,
[latestBaseBenchmarks.commit.id]: benchmark,
}
}
for (let i = 0; i < benchmarks.length; i++) {
for (const bench of benchmarks[i].benches) {
if (compareWithHead[bench.name]) {
compareWithHead[bench.name][benchmarks[i].commit.id] = bench
} else {
compareWithHead[bench.name] = {
[benchmarks[i].commit.id]: bench,
}
}
}
}
let message = '<!-- benchmark comment by ci -->\n'
const compareTableInfo = [
{
name: 'last head',
commit: lastHeadBenchmarks ? lastHeadBenchmarks.commit.id : '',
},
{
name: 'base',
commit: latestBaseBenchmarks.commit.id,
},
]
for (const benchmarkType of ['Performance', 'Memory']) {
message += `# ${benchmarkType} Benchmark\n\n`
for (const [index, compare] of [compareWithHead, compareWithBase].entries()) {
message += `## Compared with ${compareTableInfo[index].name}\n`
message += `## Benchmark\n\n`
message += '<details><summary>Detail results of benchmarks</summary>\n\n'
message += `| Benchmark suite | Current: ${latestHeadBenchmarks.commit.id} | Previous: ${compareTableInfo[index].commit} | Ratio |\n | -| -| -| -|\n`
for (const field of Object.keys(compare).filter((key) =>
benchmarkType === 'Performance' ? !key.startsWith('[Cache Plugin]') : key.startsWith('[Cache Plugin]'),
)) {
message += `| \`${field}\` | ${compare[field].current.value ? `\`${compare[field].current.value}\`` : ''} ${
compare[field].current.unit ?? ''
} ${compare[field].current.range ? `(\`${compare[field].current.range ?? ''}\`)` : ''} | ${
compare[field].previous.value ? `\`${compare[field].previous.value}\`` : ''
} ${compare[field].previous.unit ?? ''} ${compare[field].previous.range ? `(\`${compare[field].previous.range ?? ''}\`)` : ''} | ${
compare[field].previous.value && compare[field].current.value
? `\`${
// @ts-expect-error it work
Math.round((parseFloat(compare[field].previous.value) / parseFloat(compare[field].current.value)) * 100) / 100
}\``
: ''
} |\n`
let header1 = `| Benchmark suite | Base (${latestBaseBenchmarks.commit.id}) |`
let header2 = `|-|-|`
for (const [index, commitId] of benchmarks.map((benchmark) => benchmark.commit.id).entries()) {
header1 += index === 0 ? ` Latest Head (${commitId}) |` : ` ${commitId} |`
header2 += '-|'
}
message += `${header1}\n`
message += `${header2}\n`
for (const benchName of Object.keys(compareWithHead)) {
let benchData = `| ${benchName} |`
benchData += compareWithHead[benchName][latestBaseBenchmarks.commit.id]
? ` ${`\`${compareWithHead[benchName][latestBaseBenchmarks.commit.id].value}\` ${
compareWithHead[benchName][latestBaseBenchmarks.commit.id].unit
} \`${compareWithHead[benchName][latestBaseBenchmarks.commit.id].range}\``} |`
: '|'
for (const commitId of benchmarks.map((benchmark) => benchmark.commit.id)) {
benchData += compareWithHead[benchName][commitId]
? ` \`${compareWithHead[benchName][commitId].value}\` ${compareWithHead[benchName][commitId].unit} \`${compareWithHead[benchName][commitId].range}\`|`
: '|'
}
message += `${benchData}\n`
}
message += '</details>\n\n'
}
}
console.log(message.replaceAll('`', '\\`'))