-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(bench): Setup benchmark script for testing browser open timing (#…
…917)
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ docs/api/reference | |
stats.html | ||
.tool-versions | ||
.cache | ||
*-stats.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |