summaryrefslogtreecommitdiff
path: root/packages/astro/test/benchmark/dev.bench.js
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-05-26 11:31:53 -0400
committerGravatar GitHub <noreply@github.com> 2021-05-26 11:31:53 -0400
commitda47225efe5cc65cdc0e340f998a8dfbcc45771e (patch)
treedc01ddf04be0cc2a1db2f31d0f3e9910ce575b0a /packages/astro/test/benchmark/dev.bench.js
parent8a375e66d27042fe51e6d4217416962d444fad28 (diff)
downloadastro-da47225efe5cc65cdc0e340f998a8dfbcc45771e.tar.gz
astro-da47225efe5cc65cdc0e340f998a8dfbcc45771e.tar.zst
astro-da47225efe5cc65cdc0e340f998a8dfbcc45771e.zip
Add benchmarking for dev and build (#240)
* Add benchmarking for the dev server This adds benchmarking for the dev server. * Use fs.rm instead * Only rimraf if the folder exists * Make uncached match CI * Change the cached time too * Don't run benchmark in CI * Switch back test command * Make tests be within 10 percent * Use yarn to run multiple things * Turn benchmark into uvu tests * Debugging benchmark * Print chunk for testing * Ignore benchmark folder in uvu * Add build benchmarking * Update benchmark numbers
Diffstat (limited to 'packages/astro/test/benchmark/dev.bench.js')
-rw-r--r--packages/astro/test/benchmark/dev.bench.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/packages/astro/test/benchmark/dev.bench.js b/packages/astro/test/benchmark/dev.bench.js
new file mode 100644
index 000000000..e2c4d3dcd
--- /dev/null
+++ b/packages/astro/test/benchmark/dev.bench.js
@@ -0,0 +1,61 @@
+import { performance } from 'perf_hooks';
+import { Benchmark } from './benchmark.js';
+import { runDevServer } from '../helpers.js';
+import del from 'del';
+
+const snowpackExampleRoot = new URL('../../../../examples/snowpack/', import.meta.url);
+
+async function runToStarted(root) {
+ const args = [];
+ const process = runDevServer(root, args);
+
+ let started = null;
+ process.stdout.setEncoding('utf8');
+ for await (const chunk of process.stdout) {
+ if (/Server started/.test(chunk)) {
+ started = performance.now();
+ break;
+ }
+ }
+
+ process.kill();
+ return started;
+}
+
+const benchmarks = [
+ new Benchmark({
+ name: 'Snowpack Example Dev Server Uncached',
+ root: snowpackExampleRoot,
+ file: new URL('./dev-server-uncached.json', import.meta.url),
+ async setup() {
+ const spcache = new URL('../../node_modules/.cache/', import.meta.url);
+ await del(spcache.pathname);
+ },
+ run({ root }) {
+ return runToStarted(root);
+ }
+ }),
+ new Benchmark({
+ name: 'Snowpack Example Dev Server Cached',
+ root: snowpackExampleRoot,
+ file: new URL('./dev-server-cached.json', import.meta.url),
+ async setup() {
+ // Execute once to make sure Snowpack is cached.
+ await this.execute();
+ },
+ run({ root }) {
+ return runToStarted(root);
+ }
+ })
+];
+
+async function run() {
+ for(const b of benchmarks) {
+ await b.test();
+ }
+}
+
+run().catch(err => {
+ console.error(err);
+ process.exit(1);
+}); \ No newline at end of file