From cf2b803dac1e6b4e4c49f2e245a3b3a8fe01c362 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 8 Jan 2024 09:05:12 -0500 Subject: [PATCH] Expanded benchmark --- benchmark/bench/render.js | 15 +++++++++++++-- benchmark/make-project/render-default.js | 22 ++++++++++++++++------ benchmark/package.json | 3 +++ pnpm-lock.yaml | 4 ++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/benchmark/bench/render.js b/benchmark/bench/render.js index ac733bdeaa..18195ca637 100644 --- a/benchmark/bench/render.js +++ b/benchmark/bench/render.js @@ -7,6 +7,7 @@ import { fileURLToPath } from 'node:url'; import { waitUntilBusy } from 'port-authority'; import { calculateStat, astroBin } from './_util.js'; import { renderFiles } from '../make-project/render-default.js'; +import fg from 'fast-glob'; const port = 4322; @@ -35,7 +36,7 @@ export async function run(projectDir, outputFile) { await waitUntilBusy(port, { timeout: 5000 }); console.log('Running benchmark...'); - const result = await benchmarkRenderTime(); + const result = await benchmarkRenderTime(root); console.log('Killing server...'); if (!previewProcess.kill('SIGTERM')) { @@ -54,9 +55,19 @@ export async function run(projectDir, outputFile) { console.log('Done!'); } -async function benchmarkRenderTime() { +async function benchmarkRenderTime(root) { /** @type {Record} */ const result = {}; + console.log("BEFORE!"); + try { + //let entries = []; + const entries = await fg.glob(['src/pages/**/*'], { dot: true, cwd: root }); + console.log("ENTRIES", entries); + } catch(err) { + console.log("OH NO ERROR", err); + } + + for (const fileName of Object.keys(renderFiles)) { // Render each file 100 times and push to an array for (let i = 0; i < 100; i++) { diff --git a/benchmark/make-project/render-default.js b/benchmark/make-project/render-default.js index 3a01dcc479..2b3b3c8da8 100644 --- a/benchmark/make-project/render-default.js +++ b/benchmark/make-project/render-default.js @@ -4,11 +4,20 @@ import { loremIpsumHtml, loremIpsumMd } from './_util.js'; // Map of files to be generated and tested for rendering. // Ideally each content should be similar for comparison. export const renderFiles = { - 'astro.astro': `\ + 'components/ListItem.astro': `\ --- +const className = "text-red-500"; +const { item } = Astro.props; +--- +
  • {item}
  • + `, + 'pages/astro.astro': `\ +--- +import ListItem from '../components/ListItem.astro'; + const className = "text-red-500"; const style = { color: "red" }; -const items = Array.from({ length: 1000 }, (_, i) => i); +const items = Array.from({ length: 3000 }, (_, i) => i); --- @@ -19,7 +28,7 @@ const items = Array.from({ length: 1000 }, (_, i) => i);

    List

    ${Array.from({ length: 1000 }) @@ -27,7 +36,7 @@ const items = Array.from({ length: 1000 }, (_, i) => i); .join('\n')} `, - 'md.md': `\ + 'pages/md.md': `\ # List ${Array.from({ length: 1000 }, (_, i) => i) @@ -38,7 +47,7 @@ ${Array.from({ length: 1000 }) .map(() => loremIpsumMd) .join('\n\n')} `, - 'mdx.mdx': `\ + 'pages/mdx.mdx': `\ export const className = "text-red-500"; export const style = { color: "red" }; export const items = Array.from({ length: 1000 }, (_, i) => i); @@ -63,10 +72,11 @@ ${Array.from({ length: 1000 }) 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 Promise.all( Object.entries(renderFiles).map(([name, content]) => { - return fs.writeFile(new URL(`./src/pages/${name}`, projectDir), content, 'utf-8'); + return fs.writeFile(new URL(`./src/${name}`, projectDir), content, 'utf-8'); }) ); diff --git a/benchmark/package.json b/benchmark/package.json index 55848222ed..f6adcb5d21 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -17,5 +17,8 @@ "mri": "^1.2.0", "port-authority": "^2.0.1", "pretty-bytes": "^6.1.1" + }, + "devDependencies": { + "fast-glob": "^3.3.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 260a33c040..bc64eac34d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,10 @@ importers: pretty-bytes: specifier: ^6.1.1 version: 6.1.1 + devDependencies: + fast-glob: + specifier: ^3.3.2 + version: 3.3.2 benchmark/packages/timer: dependencies: