summaryrefslogtreecommitdiff
path: root/benchmark/bench/codspeed.js
diff options
context:
space:
mode:
authorGravatar bluwy <bjornlu.dev@gmail.com> 2024-11-06 23:17:39 +0800
committerGravatar bluwy <bjornlu.dev@gmail.com> 2024-11-06 23:17:39 +0800
commit7db86cf2b75c547b5947bc1a10f21d2e3e56e9da (patch)
tree115d93a2565958a069462d4e39446059e6395339 /benchmark/bench/codspeed.js
parentc280655655cc6c22121f32c5f7c76836adf17230 (diff)
parente10b03e88c22592fbb42d7245b65c4f486ab736d (diff)
downloadastro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.tar.gz
astro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.tar.zst
astro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.zip
Merge branch 'main' into next
Diffstat (limited to 'benchmark/bench/codspeed.js')
-rw-r--r--benchmark/bench/codspeed.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/benchmark/bench/codspeed.js b/benchmark/bench/codspeed.js
new file mode 100644
index 000000000..2ad783e8a
--- /dev/null
+++ b/benchmark/bench/codspeed.js
@@ -0,0 +1,50 @@
+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 () => {
+ 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);
+ }
+ console.info('Finish task.');
+ return result;
+ },
+ {
+ async beforeAll() {
+ // build for rendering
+ 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);
+ app = createApp(manifest);
+ app.manifest = manifest;
+ },
+ },
+ );
+
+ await bench.run();
+ console.table(bench.table());
+}