diff options
author | 2024-11-06 23:17:39 +0800 | |
---|---|---|
committer | 2024-11-06 23:17:39 +0800 | |
commit | 7db86cf2b75c547b5947bc1a10f21d2e3e56e9da (patch) | |
tree | 115d93a2565958a069462d4e39446059e6395339 /benchmark/index.js | |
parent | c280655655cc6c22121f32c5f7c76836adf17230 (diff) | |
parent | e10b03e88c22592fbb42d7245b65c4f486ab736d (diff) | |
download | astro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.tar.gz astro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.tar.zst astro-7db86cf2b75c547b5947bc1a10f21d2e3e56e9da.zip |
Merge branch 'main' into next
Diffstat (limited to 'benchmark/index.js')
-rwxr-xr-x | benchmark/index.js | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/benchmark/index.js b/benchmark/index.js index 1c38993b1..2f2846e1d 100755 --- a/benchmark/index.js +++ b/benchmark/index.js @@ -1,7 +1,7 @@ import mri from 'mri'; import fs from 'node:fs/promises'; import path from 'node:path'; -import { pathToFileURL } from 'node:url'; +import {fileURLToPath, pathToFileURL} from 'node:url'; const args = mri(process.argv.slice(2)); @@ -14,6 +14,7 @@ Command memory Run build memory and speed test render Run rendering speed test server-stress Run server stress test + codspeed Run codspeed test cli-startup Run CLI startup speed test Options @@ -29,6 +30,7 @@ const benchmarks = { render: () => import('./bench/render.js'), 'server-stress': () => import('./bench/server-stress.js'), 'cli-startup': () => import('./bench/cli-startup.js'), + codspeed: () => import('./bench/codspeed.js') }; if (commandName && !(commandName in benchmarks)) { @@ -37,12 +39,26 @@ if (commandName && !(commandName in benchmarks)) { } if (commandName) { - // Run single benchmark - const bench = benchmarks[commandName]; - const benchMod = await bench(); - const projectDir = await makeProject(args.project || benchMod.defaultProject); - const outputFile = await getOutputFile(commandName); - await benchMod.run(projectDir, outputFile); + if (commandName === 'codspeed') { + const render = await makeProject('render-bench'); + const rootRender = fileURLToPath(render); + const bench = benchmarks[commandName]; + const benchMod = await bench(); + const payload = { + render: { + root: rootRender, + output: await getOutputFile('render') + }, + }; + await benchMod.run(payload); + } else { + // Run single benchmark + const bench = benchmarks[commandName]; + const benchMod = await bench(); + const projectDir = await makeProject(args.project || benchMod.defaultProject); + const outputFile = await getOutputFile(commandName); + await benchMod.run(projectDir, outputFile); + } } else { // Run all benchmarks for (const name in benchmarks) { @@ -54,7 +70,7 @@ if (commandName) { } } -async function makeProject(name) { +export async function makeProject(name) { console.log('Making project:', name); const projectDir = new URL(`./projects/${name}/`, import.meta.url); @@ -78,6 +94,5 @@ async function getOutputFile(benchmarkName) { // Prepare output file directory await fs.mkdir(new URL('./', file), { recursive: true }); - return file; } |