Skip to content
Merged
54 changes: 54 additions & 0 deletions resources/benchmark-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,58 @@ class PageElement {
}
}

// The WarmupSuite is used to make sure all runner helper functions and
// classes are compiled, to avoid unnecessary pauses due to delayed
// compilation of runner methods in the middle of the measuring cycle.
const WarmupSuite = {
name: "Warmup",
url: "warmup/index.html",
async prepare(page) {
await page.waitForElement("#testItem");
},
tests: [
// Make sure to run ever page.method once at least
new BenchmarkTestStep("WarmingUpPageMethods", (page) => {
let results = [];
results.push(page.querySelector(".testItem"));
results.push(page.querySelectorAll(".item"));
results.push(page.getElementById("testItem"));
}),
new BenchmarkTestStep("WarmingUpPageElementMethods", (page) => {
const item = page.getElementById("testItem");
item.setValue("value");
item.click();
item.focus();
item.dispatchEvent("change");
item.enter("keypress");
item.dispatchEvent("input");
item.enter("keyup");
}),
new BenchmarkTestStep("WarmingUpPageElementMouseMethods", (page) => {
const item = page.getElementById("testItem");
const mouseEventOptions = { clientX: 100, clientY: 100, bubbles: true, cancelable: true };
const wheelEventOptions = {
clientX: 200,
clientY: 200,
deltaMode: 0,
delta: -10,
deltaY: -10,
bubbles: true,
cancelable: true,
};
item.dispatchEvent("mousedown", mouseEventOptions, MouseEvent);
item.dispatchEvent("mousemove", mouseEventOptions, MouseEvent);
item.dispatchEvent("mouseup", mouseEventOptions, MouseEvent);
item.dispatchEvent("wheel", wheelEventOptions, WheelEvent);
}),
],
};

export class BenchmarkRunner {
constructor(suites, client) {
this._suites = suites;
if (params.useWarmupSuite)
this._suites = [WarmupSuite, ...suites];
this._client = client;
this._page = null;
this._metrics = {
Expand Down Expand Up @@ -263,6 +312,11 @@ export class BenchmarkRunner {
}

async _recordTestResults(suite, test, syncTime, asyncTime, unused_height, testDoneCallback) {
// Skip reporting updates for the warmup suite.
if (suite === WarmupSuite) {
testDoneCallback();
return;
}
const suiteResults = this._measuredValues.tests[suite.name] || { tests: {}, total: 0 };
const total = syncTime + asyncTime;
this._measuredValues.tests[suite.name] = suiteResults;
Expand Down
6 changes: 6 additions & 0 deletions resources/params.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Params {
startAutomatically = false;
iterationCount = 10;
suites = [];
useWarmupSuite = false;

constructor(searchParams = undefined) {
if (searchParams)
Expand Down Expand Up @@ -48,6 +49,11 @@ class Params {
const unused = Array.from(searchParams.keys());
if (unused.length > 0)
console.error("Got unused search params", unused);

if (searchParams.has("useWarmupSuite")) {
this.useWarmupSuite = true;
searchParams.delete("useWarmupSuite");
}
}

toSearchParams() {
Expand Down
18 changes: 18 additions & 0 deletions resources/warmup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Warmup Page</title>
</head>
<body style="background-color: white">
<h1>WARMUP</h1>
<div>
<div class="item">item 1</div>
<div class="item">item 2</div>
<div class="item">item 3</div>
<div class="item">item 4</div>
<div class="item">item 5</div>
<div class="item" id="testItem">item 6</div>
</div>
</body>
</html>