Skip to content

Commit

Permalink
feat: add last update time at /benchmarks page, clse fastify#176
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoturi committed Mar 11, 2024
1 parent c3767ce commit f7de1e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 13 additions & 3 deletions scripts/download-benchmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ async function execute({ downloadUrl, outputFile }) {
async function downloadBenchmarks(githubUrl) {
const data = await getDataAsJSON(githubUrl)
if (isValidBenchmark(data)) {
return buildBenchmarksJSON(data)
const date = await getBenchmarkDate();
return buildBenchmarksJSON(data, date);
}

log.warn('Fetched file contains `N/A` data. Searching for previous revision')

const commits = await getCommits()
let i = 0;
for (let commit in commits) {
const commitSha = commits[commit]
log.debug(`Checking commit %s`, commitSha)
Expand All @@ -59,13 +61,20 @@ async function downloadBenchmarks(githubUrl) {

const data = await getBlob(benchmarlUrl)
if (isValidBenchmark(data)) {
return buildBenchmarksJSON(data)
const date = await getBenchmarkDate(i);
return buildBenchmarksJSON(data, date);
}
i++;
}

throw new Error('Unable to find a valid benchmark result')
}

async function getBenchmarkDate(benchmarkCommitNumber=0) {
const commits = await getDataAsJSON(`${GITHUB_BASE_URL}/commits?path=benchmark-results.json&per_page=10`);
return commits[benchmarkCommitNumber] ? commits[benchmarkCommitNumber].commit.committer.date : 'Unknown';
}

const getCommits = async () => {
const commits = await getDataAsJSON(`${GITHUB_BASE_URL}/commits?path=benchmark-results.json&per_page=10`)
return commits.map((commit) => commit.sha)
Expand All @@ -87,13 +96,14 @@ const getBlob = async (blobUrl) => {
return JSON.parse(decodedContent)
}

function buildBenchmarksJSON(data) {
function buildBenchmarksJSON(data, date = 'Unknown') {
const maxSpeed = data
.filter(({ requests }) => !isNaN(requests))
.map(({ requests }) => parseInt(requests))
.reduce((max, req) => (req > max ? req : max), 0)

const json = {
date,
reference: maxSpeed,
frameworks: arrayDefaultFrameworks.map((framework) => {
const item = data.find(({ name }) => name == framework.tag)
Expand Down
6 changes: 5 additions & 1 deletion src/pages/benchmarks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ export function BenchmarkSection() {
))
}

export function BenchMarkDate() {
return benchmarksData.date === 'Unknown' ? 'Unknown' : (new Date(benchmarksData.date)).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
}

<HeroBanner title="Benchmarks" />

Leveraging our experience with Node.js performance, Fastify has been built from the ground up to be **as fast as possible**.

All the code used for our benchmarks is [available on GitHub](https://github.com/fastify/benchmarks/).

Here's a brief summary on how Fastify overhead performed against the some other well known Node.js web frameworks:
Here's a brief summary on how Fastify overhead performed against the some other well known Node.js web frameworks (last updated on <BenchMarkDate />):

<BenchmarkSection />

Expand Down

0 comments on commit f7de1e8

Please sign in to comment.