chore(bench): Setup benchmark script for testing browser open timing (#917)

This commit is contained in:
Aaron
2024-08-15 16:51:06 -05:00
committed by GitHub
parent 8235de04d2
commit a1fc19e47c
3 changed files with 68 additions and 0 deletions
+1
View File
@@ -21,3 +21,4 @@ docs/api/reference
stats.html
.tool-versions
.cache
*-stats.txt
+26
View File
@@ -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() {
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
set -e
#
# Benchmark how long it takes for the browser to open in dev mode.
#
# To run:
# cd <root>
# ./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"