mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
feat: Add timeline benchmark
This commit is contained in:
parent
15ef1851fc
commit
df5e8f744b
4 changed files with 74 additions and 1 deletions
56
benchmarks/timelines.ts
Normal file
56
benchmarks/timelines.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Usage: TOKEN=your_token_here bun benchmark:timeline <request_count>
|
||||
*/
|
||||
|
||||
import { getConfig } from "@config";
|
||||
import chalk from "chalk";
|
||||
|
||||
const config = getConfig();
|
||||
|
||||
const token = process.env.TOKEN;
|
||||
const requestCount = Number(process.argv[2]) || 100;
|
||||
|
||||
if (!token) {
|
||||
console.log(
|
||||
`${chalk.red(
|
||||
"✗"
|
||||
)} No token provided. Provide one via the TOKEN environment variable.`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const fetchTimeline = () =>
|
||||
fetch(`${config.http.base_url}/api/v1/timelines/home`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}).then(res => res.ok);
|
||||
|
||||
const timeNow = performance.now();
|
||||
|
||||
const requests = Array.from({ length: requestCount }, () => fetchTimeline());
|
||||
|
||||
Promise.all(requests)
|
||||
.then(results => {
|
||||
const timeTaken = performance.now() - timeNow;
|
||||
if (results.every(t => t)) {
|
||||
console.log(`${chalk.green("✓")} All requests succeeded`);
|
||||
} else {
|
||||
console.log(
|
||||
`${chalk.red("✗")} ${
|
||||
results.filter(t => !t).length
|
||||
} requests failed`
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`${chalk.green("✓")} ${
|
||||
requests.length
|
||||
} requests fulfilled in ${chalk.bold(
|
||||
(timeTaken / 1000).toFixed(5)
|
||||
)}s`
|
||||
);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(`${chalk.red("✗")} ${err}`);
|
||||
process.exit(1);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue