summaryrefslogtreecommitdiff
path: root/benchmark/bench/codspeed.js
diff options
context:
space:
mode:
authorGravatar bluwy <bjornlu.dev@gmail.com> 2024-11-15 19:37:28 +0800
committerGravatar bluwy <bjornlu.dev@gmail.com> 2024-11-15 19:37:28 +0800
commit671f50c7d3c02ab9d23d8d38ecb8934d080b6a40 (patch)
tree45af7931d284ee47857c9bc5c172f12eff779b2f /benchmark/bench/codspeed.js
parent4364bff27332e52f92da72392620a36110daee42 (diff)
parent55091174158a80f2e023571f6d10ffdbf17d274b (diff)
downloadastro-671f50c7d3c02ab9d23d8d38ecb8934d080b6a40.tar.gz
astro-671f50c7d3c02ab9d23d8d38ecb8934d080b6a40.tar.zst
astro-671f50c7d3c02ab9d23d8d38ecb8934d080b6a40.zip
Merge branch 'main' into next
Diffstat (limited to 'benchmark/bench/codspeed.js')
-rw-r--r--benchmark/bench/codspeed.js78
1 files changed, 46 insertions, 32 deletions
diff --git a/benchmark/bench/codspeed.js b/benchmark/bench/codspeed.js
index 2ad783e8a..2643b1ec8 100644
--- a/benchmark/bench/codspeed.js
+++ b/benchmark/bench/codspeed.js
@@ -2,7 +2,6 @@ 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 }) {
@@ -10,40 +9,55 @@ export async function run({ memory: _memory, render, stress: _stress }) {
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());