Skip to content

Commit

Permalink
chore(bench): Setup benchmark script for testing browser open timing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 authored Aug 15, 2024
1 parent 8235de0 commit a1fc19e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ docs/api/reference
stats.html
.tool-versions
.cache
*-stats.txt
26 changes: 26 additions & 0 deletions scripts/benchmarks/browser-startup.patch
Original file line number Diff line number Diff line change
@@ -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 changes: 41 additions & 0 deletions scripts/benchmarks/browser-startup.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a1fc19e

Please sign in to comment.