From 0ae3b7a7ba1bd999608f10666dd454a91b811f9e Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 25 Aug 2023 21:00:51 +0800 Subject: [PATCH] Improve stress test benchmark (#8225) --- benchmark/bench/_util.js | 7 +++++-- benchmark/make-project/server-stress-default.js | 13 ++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/benchmark/bench/_util.js b/benchmark/bench/_util.js index c9108695c..23c472604 100644 --- a/benchmark/bench/_util.js +++ b/benchmark/bench/_util.js @@ -1,6 +1,9 @@ -import { createRequire } from 'module'; +import { createRequire } from 'node:module'; +import path from 'node:path'; -export const astroBin = createRequire(import.meta.url).resolve('astro'); +const astroPkgPath = createRequire(import.meta.url).resolve('astro/package.json'); + +export const astroBin = path.resolve(astroPkgPath, '../astro.js'); /** @typedef {{ avg: number, stdev: number, max: number }} Stat */ diff --git a/benchmark/make-project/server-stress-default.js b/benchmark/make-project/server-stress-default.js index 20094daa6..cbeeeda3b 100644 --- a/benchmark/make-project/server-stress-default.js +++ b/benchmark/make-project/server-stress-default.js @@ -7,11 +7,13 @@ import { loremIpsum } from './_util.js'; export async function run(projectDir) { await fs.rm(projectDir, { recursive: true, force: true }); await fs.mkdir(new URL('./src/pages', projectDir), { recursive: true }); + await fs.mkdir(new URL('./src/components', projectDir), { recursive: true }); await fs.writeFile( new URL('./src/pages/index.astro', projectDir), `\ --- +import Paragraph from '../components/Paragraph.astro' const content = "${loremIpsum}" --- @@ -25,13 +27,22 @@ const content = "${loremIpsum}"

Astro

- ${Array.from({ length: 60 }).map(() => '

{content}

')} + ${Array.from({ length: 100 }).map(() => '

{content}

').join('\n')} +
+
+ ${Array.from({ length: 50 }).map((_, i) => '').join('\n')}
`, 'utf-8' ); + await fs.writeFile( + new URL('./src/components/Paragraph.astro', projectDir), + `
{Astro.props.num} {Astro.props.str}
`, + 'utf-8' + ); + await fs.writeFile( new URL('./astro.config.js', projectDir), `\