Files
discordeno/scripts/generateMessage.js
Fleny 27c261fee2 formatter: Use semicolons (#4686)
I prefer semicolors, they also help avoiding certain pitfalls in JavaScript/TypeScript, such as the following code sample:
```js
const xyz = "test"
(something.else as string) = "another"
```
This results in a TypeError: "test" is not a function, this is because js thinks we are trying to call the string "test" as a function.
To fix this it requires a `;` somewhere before the `(`, such as `;(something ... ` which in my opinion is ugly and less clean overall.
2026-01-17 21:54:15 +01:00

57 lines
2.4 KiB
JavaScript

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)));
// const commitSha = await fs.readFile('./sha', 'utf-8')
const results = JSON.parse(await fs.readFile('./data.json', 'utf-8'));
const benchmarks = results.entries.Benchmark;
benchmarks.reverse();
const compareWithHead = {};
const latestBaseBenchmarks = benchmarkData.entries.Benchmark.slice(-1)[0];
for (const benchmark of latestBaseBenchmarks.benches) {
compareWithHead[benchmark.name] = {
[latestBaseBenchmarks.commit.id]: benchmark,
};
}
for (let i = benchmarks.length - 1; i >= 0; 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 = `|-|-|`;
const commitIds = benchmarks.map((benchmark) => benchmark.commit.id);
const uniqueCommitIds = commitIds.filter((benchmarkCommitId, index) => commitIds.indexOf(benchmarkCommitId) === index);
for (const [index, commitId] of uniqueCommitIds.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 uniqueCommitIds) {
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('`', '\\`'));