-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lysand-org/main
v0.1.2
- Loading branch information
Showing
16 changed files
with
676 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
Oops, something went wrong.