Skip to content

Commit

Permalink
chore: breakdown of benchmarks (withastro#12433)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Nov 14, 2024
1 parent 9fc2ab8 commit e64ec5f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 34 deletions.
78 changes: 46 additions & 32 deletions benchmark/bench/codspeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,62 @@ import path from 'node:path';
import { withCodSpeed } from '@codspeed/tinybench-plugin';
import { Bench } from 'tinybench';
import { exec } from 'tinyexec';
import { renderPages } from '../make-project/render-default.js';
import { astroBin } from './_util.js';

export async function run({ memory: _memory, render, stress: _stress }) {
const options = {
iterations: 10,
};
const bench = process.env.CODSPEED ? withCodSpeed(new Bench(options)) : new Bench(options);
let app;
bench.add(
'Rendering',
async () => {
await exec(astroBin, ['build'], {
nodeOptions: {
cwd: render.root,
stdio: 'inherit',
},
});

const entry = new URL('./dist/server/entry.mjs', `file://${render.root}`);
const { manifest, createApp } = await import(entry);
const streamingApp = createApp(manifest, true);
const nonStreamingApp = createApp(manifest, false);
bench
.add('Rendering: streaming [true], .astro file', async () => {
console.info('Start task.');
const result = {};
for (const fileName of renderPages) {
const pathname = '/' + fileName.slice(0, -path.extname(fileName).length);
const request = new Request(new URL(pathname, 'http://exmpale.com'));
const response = await app.render(request);
const html = await response.text();
if (!result[pathname]) result[pathname] = [];
result[pathname].push(html);
}
const request = new Request(new URL('http://exmpale.com/astro'));
await streamingApp.render(request);
console.info('Finish task.');
return result;
},
{
async beforeAll() {
// build for rendering
await exec(astroBin, ['build'], {
nodeOptions: {
cwd: render.root,
stdio: 'inherit',
},
});
})
.add('Rendering: streaming [true], .md file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/md'));
await streamingApp.render(request);
console.info('Finish task.');
})
.add('Rendering: streaming [true], .mdx file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/mdx'));
await streamingApp.render(request);
console.info('Finish task.');
})

const entry = new URL('./dist/server/entry.mjs', `file://${render.root}`);
const { manifest, createApp } = await import(entry);
app = createApp(manifest);
app.manifest = manifest;
},
},
);
.add('Rendering: streaming [false], .astro file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/astro'));
await nonStreamingApp.render(request);
console.info('Finish task.');
})
.add('Rendering: streaming [false], .md file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/md'));
await nonStreamingApp.render(request);
console.info('Finish task.');
})
.add('Rendering: streaming [false], .mdx file', async () => {
console.info('Start task.');
const request = new Request(new URL('http://exmpale.com/mdx'));
await nonStreamingApp.render(request);
console.info('Finish task.');
});

await bench.run();
console.table(bench.table());
Expand Down
2 changes: 0 additions & 2 deletions benchmark/packages/adapter/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ applyPolyfills();

class MyApp extends App {
#manifest: SSRManifest | undefined;
#streaming: boolean;
constructor(manifest: SSRManifest, streaming = false) {
super(manifest, streaming);
this.#manifest = manifest;
this.#streaming = streaming;
}

async render(request: Request) {
Expand Down

0 comments on commit e64ec5f

Please sign in to comment.