Skip to content

Commit

Permalink
chore: add numPosts as a benchmark flag
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Mar 7, 2023
1 parent 06a0e2f commit ad20691
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions packages/astro/performance/content-benchmark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ const extByFixture = {
mdoc: '.mdoc',
};

const NUM_POSTS = 1000;

async function benchmark({ fixtures, templates }) {
async function benchmark({ fixtures, templates, numPosts }) {
for (const fixture of fixtures) {
const root = new URL(`./fixtures/${fixture}/`, import.meta.url);
await generatePosts({
postsDir: fileURLToPath(new URL('./src/content/generated/', root)),
numPosts: NUM_POSTS,
numPosts,
ext: extByFixture[fixture],
template: templates[fixture],
});
Expand Down Expand Up @@ -55,10 +53,12 @@ async function benchmark({ fixtures, templates }) {
? [flags.format]
: ['md', 'mdx', 'mdoc'];

const numPosts = flags.numPosts || 1000;

if (test.includes('simple')) {
const fixtures = formats;
console.log(
`\n${bold('Simple')} ${dim(`${NUM_POSTS} posts (${formatsToString(fixtures)})`)}`
`\n${bold('Simple')} ${dim(`${numPosts} posts (${formatsToString(fixtures)})`)}`
);
process.env.ASTRO_PERFORMANCE_TEST_NAME = 'simple';
await benchmark({
Expand All @@ -68,14 +68,15 @@ async function benchmark({ fixtures, templates }) {
mdx: 'simple.md',
mdoc: 'simple.md',
},
numPosts,
});
}

if (test.includes('with-astro-components')) {
const fixtures = formats.filter((format) => format !== 'md');
console.log(
`\n${bold('With Astro components')} ${dim(
`${NUM_POSTS} posts (${formatsToString(fixtures)})`
`${numPosts} posts (${formatsToString(fixtures)})`
)}`
);
process.env.ASTRO_PERFORMANCE_TEST_NAME = 'with-astro-components';
Expand All @@ -85,14 +86,15 @@ async function benchmark({ fixtures, templates }) {
mdx: 'with-astro-components.mdx',
mdoc: 'with-astro-components.mdoc',
},
numPosts,
});
}

if (test.includes('with-react-components')) {
const fixtures = formats.filter((format) => format !== 'md');
console.log(
`\n${bold('With React components')} ${dim(
`${NUM_POSTS} posts (${formatsToString(fixtures)})`
`${numPosts} posts (${formatsToString(fixtures)})`
)}`
);
process.env.ASTRO_PERFORMANCE_TEST_NAME = 'with-react-components';
Expand All @@ -102,6 +104,7 @@ async function benchmark({ fixtures, templates }) {
mdx: 'with-react-components.mdx',
mdoc: 'with-react-components.mdoc',
},
numPosts,
});
}
} finally {
Expand Down

0 comments on commit ad20691

Please sign in to comment.