mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Fix(bench): wrong location (#2932)
* Update commentBenchResult.yml * ci: fix ext * refactor(bench): better table
This commit is contained in:
@@ -67,7 +67,7 @@ jobs:
|
|||||||
- name: Generate Message
|
- name: Generate Message
|
||||||
id: genMessage
|
id: genMessage
|
||||||
run: |
|
run: |
|
||||||
MESSAGE=$(deno run -A performance/generateMessage.ts)
|
MESSAGE=$(deno run -A scripts/generateMessage.js)
|
||||||
echo "MESSAGE<<EOF" >> $GITHUB_ENV
|
echo "MESSAGE<<EOF" >> $GITHUB_ENV
|
||||||
echo "$MESSAGE" >> $GITHUB_ENV
|
echo "$MESSAGE" >> $GITHUB_ENV
|
||||||
echo "EOF" >> $GITHUB_ENV
|
echo "EOF" >> $GITHUB_ENV
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"fmt": "eslint --fix \"src/**/*.ts*\"",
|
"fmt": "eslint --fix \"src/**/*.ts*\"",
|
||||||
"lint": "eslint \"src/**/*.ts*\"",
|
"lint": "eslint \"src/**/*.ts*\"",
|
||||||
"build": "swc src --delete-dir-on-start --out-dir dist && node ../../scripts/fixBenchExtension.js",
|
"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"
|
"bench": "node dist/index.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -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('`', '\\`'))
|
|
||||||
+39
-63
@@ -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`)
|
const benchmarkData = await fetch(`https://raw.githubusercontent.com/discordeno/discordeno/benchies/benchmarksResult/data.js`)
|
||||||
.then(async (res) => await res.text())
|
.then(async (res) => await res.text())
|
||||||
.then((text) => JSON.parse(text.slice(24)))
|
.then((text) => JSON.parse(text.slice(24)))
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
|
||||||
const commitSha = await fs.readFile('./sha', 'utf-8')
|
const commitSha = await fs.readFile('./sha', 'utf-8')
|
||||||
const results = JSON.parse(await fs.readFile('./data.json', 'utf-8'))
|
const results = JSON.parse(await fs.readFile('./data.json', 'utf-8'))
|
||||||
const benchmarks = results.entries.Benchmark.slice(-2)
|
const benchmarks = results.entries.Benchmark
|
||||||
const latestHeadBenchmarks = benchmarks.length === 2 ? benchmarks[1] : benchmarks[0]
|
benchmarks.reverse()
|
||||||
const lastHeadBenchmarks = benchmarks.length === 2 ? benchmarks[0] : undefined
|
|
||||||
const latestBaseBenchmarks = JSON.parse(JSON.stringify(benchmarkData.entries.Benchmark)).slice(-1)[0]
|
|
||||||
const compareWithHead = {}
|
const compareWithHead = {}
|
||||||
const compareWithBase = {}
|
const latestBaseBenchmarks = benchmarkData.entries.Benchmark.slice(-1)[0]
|
||||||
if (lastHeadBenchmarks) {
|
|
||||||
for (const benchmark of lastHeadBenchmarks.benches) {
|
|
||||||
compareWithHead[benchmark.name] = {
|
|
||||||
previous: benchmark,
|
|
||||||
current: {},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (const benchmark of latestBaseBenchmarks.benches) {
|
for (const benchmark of latestBaseBenchmarks.benches) {
|
||||||
compareWithBase[benchmark.name] = {
|
compareWithHead[benchmark.name] = {
|
||||||
previous: benchmark,
|
[latestBaseBenchmarks.commit.id]: benchmark,
|
||||||
current: {},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const benchmark of latestHeadBenchmarks.benches) {
|
for (let i = 0; i < benchmarks.length; i++) {
|
||||||
compareWithBase[benchmark.name] = {
|
for (const bench of benchmarks[i].benches) {
|
||||||
// @ts-expect-error it should work
|
if (compareWithHead[bench.name]) {
|
||||||
previous: {},
|
compareWithHead[bench.name][benchmarks[i].commit.id] = bench
|
||||||
...compareWithBase[benchmark.name],
|
} else {
|
||||||
current: benchmark,
|
compareWithHead[bench.name] = {
|
||||||
}
|
[benchmarks[i].commit.id]: bench,
|
||||||
compareWithHead[benchmark.name] = {
|
}
|
||||||
// @ts-expect-error it should work
|
}
|
||||||
previous: {},
|
|
||||||
...compareWithHead[benchmark.name],
|
|
||||||
current: benchmark,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let message = '<!-- benchmark comment by ci -->\n'
|
let message = '<!-- benchmark comment by ci -->\n'
|
||||||
const compareTableInfo = [
|
message += `## Benchmark\n\n`
|
||||||
{
|
message += '<details><summary>Detail results of benchmarks</summary>\n\n'
|
||||||
name: 'last head',
|
let header1 = `| Benchmark suite | Base (${latestBaseBenchmarks.commit.id}) |`
|
||||||
commit: lastHeadBenchmarks ? lastHeadBenchmarks.commit.id : '',
|
let header2 = `|-|-|`
|
||||||
},
|
for (const [index, commitId] of benchmarks.map((benchmark) => benchmark.commit.id).entries()) {
|
||||||
{
|
header1 += index === 0 ? ` Latest Head (${commitId}) |` : ` ${commitId} |`
|
||||||
name: 'base',
|
header2 += '-|'
|
||||||
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'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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('`', '\\`'))
|
console.log(message.replaceAll('`', '\\`'))
|
||||||
|
|||||||
Reference in New Issue
Block a user