0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Expanded benchmark

This commit is contained in:
Matthew Phillips 2024-01-08 09:05:12 -05:00
parent 47b951b388
commit cf2b803dac
4 changed files with 36 additions and 8 deletions

View file

@ -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<string, number[]>} */
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++) {

View file

@ -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;
---
<li class={className}>{item}</li>
`,
'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);
---
<html>
@ -19,7 +28,7 @@ const items = Array.from({ length: 1000 }, (_, i) => i);
<h1 class={className + ' text-lg'}>List</h1>
<ul style={style}>
{items.map((item) => (
<li class={className}>{item}</li>
<ListItem item={item} />
))}
</ul>
${Array.from({ length: 1000 })
@ -27,7 +36,7 @@ const items = Array.from({ length: 1000 }, (_, i) => i);
.join('\n')}
</body>
</html>`,
'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');
})
);

View file

@ -17,5 +17,8 @@
"mri": "^1.2.0",
"port-authority": "^2.0.1",
"pretty-bytes": "^6.1.1"
},
"devDependencies": {
"fast-glob": "^3.3.2"
}
}

View file

@ -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: