diff --git a/.gitignore b/.gitignore index 60fe67a3a..f8387094c 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ docs/api/reference stats.html .tool-versions .cache +*-stats.txt diff --git a/scripts/benchmarks/browser-startup.patch b/scripts/benchmarks/browser-startup.patch new file mode 100644 index 000000000..cb6ae14b7 --- /dev/null +++ b/scripts/benchmarks/browser-startup.patch @@ -0,0 +1,26 @@ +diff --git a/packages/wxt/src/core/runners/web-ext.ts b/packages/wxt/src/core/runners/web-ext.ts +index 09819c3..a0f0df2 100644 +--- a/packages/wxt/src/core/runners/web-ext.ts ++++ b/packages/wxt/src/core/runners/web-ext.ts +@@ -3,6 +3,8 @@ import { ExtensionRunner } from '../../types'; + import { formatDuration } from '../utils/time'; + import defu from 'defu'; + import { wxt } from '../wxt'; ++import fs from 'node:fs'; ++import stream from 'node:stream/promises'; + + /** + * Create an `ExtensionRunner` backed by `web-ext`. +@@ -78,6 +80,12 @@ export function createWebExtRunner(): ExtensionRunner { + + const duration = Date.now() - startTime; + wxt.logger.success(`Opened browser in ${formatDuration(duration)}`); ++ await runner.exit(); ++ const s = fs.createWriteStream('stats.txt', { flags: 'a' }); ++ s.write(duration + ' '); ++ s.end(); ++ await stream.finished(s); ++ process.exit(0); + }, + + async closeBrowser() { diff --git a/scripts/benchmarks/browser-startup.sh b/scripts/benchmarks/browser-startup.sh new file mode 100755 index 000000000..ee5b2e11f --- /dev/null +++ b/scripts/benchmarks/browser-startup.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -e + +# +# Benchmark how long it takes for the browser to open in dev mode. +# +# To run: +# cd +# ./scripts/benchmarks/browser-startup.sh +# +# You can set N below to change the number of samples per git ref. +# + +N=20 + +function benchmark_ref() { + # Prep + git checkout $1 + pnpm buildc clean + git apply scripts/benchmarks/browser-startup.patch + pnpm i --ignore-scripts + pnpm -r --filter wxt build + echo -n "$1 " >> stats.txt + + # Run benchmark + for i in $(seq $N); do + pnpm wxt packages/wxt-demo + done + git checkout HEAD -- packages/wxt/src/core/runners/web-ext.ts pnpm-lock.yaml + echo "" >> stats.txt +} + +rm -f stats.txt + +benchmark_ref "HEAD" + +# Benchmark a commit: +# benchmark_ref "3109bba" +# +# Benchmark a version: +# benchmark_ref "v0.19.0"