Skip to content

Commit

Permalink
Add local results variable to SuiteRunner (#445)
Browse files Browse the repository at this point in the history
We can migrate some of the measuredValue logic directly to the SuiteRunner and simplify the code a bit.
Additionally this will allow us to generate more flexible metrics in the future.
  • Loading branch information
camillobruni authored Nov 4, 2024
1 parent 04cfe65 commit 1552769
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions resources/benchmark-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ export class BenchmarkRunner {
export class SuiteRunner {
constructor(measuredValues, frame, page, client, suite) {
// FIXME: Create SuiteRunner-local measuredValues.
this._suiteResults = measuredValues.tests[suite.name];
if (!this._suiteResults) {
this._suiteResults = { tests: {}, total: 0 };
measuredValues.tests[suite.name] = this._suiteResults;
}
this._measuredValues = measuredValues;
this._frame = frame;
this._page = page;
Expand Down Expand Up @@ -579,17 +584,16 @@ export class SuiteRunner {
performance.mark(suiteEndLabel);

performance.measure(`suite-${suiteName}`, suiteStartLabel, suiteEndLabel);
this._validateSuiteTotal(suiteName);
this._validateSuiteTotal();
}

_validateSuiteTotal() {
// When the test is fast and the precision is low (for example with Firefox'
// privacy.resistFingerprinting preference), it's possible that the measured
// total duration for an entire is 0.
const suiteName = this._suite.name;
const suiteTotal = this._measuredValues.tests[suiteName].total;
const suiteTotal = this._suiteResults.total;
if (suiteTotal === 0)
throw new Error(`Got invalid 0-time total for suite ${suiteName}: ${suiteTotal}`);
throw new Error(`Got invalid 0-time total for suite ${this._suite.name}: ${suiteTotal}`);
}

async _loadFrame() {
Expand Down Expand Up @@ -663,12 +667,10 @@ export class SuiteRunner {
// Skip reporting updates for the warmup suite.
if (this._suite === WarmupSuite)
return;
const suiteName = this._suite.name;
const suiteResults = this._measuredValues.tests[suiteName] || { tests: {}, total: 0 };

const total = syncTime + asyncTime;
this._measuredValues.tests[suiteName] = suiteResults;
suiteResults.tests[test.name] = { tests: { Sync: syncTime, Async: asyncTime }, total: total };
suiteResults.total += total;
this._suiteResults.tests[test.name] = { tests: { Sync: syncTime, Async: asyncTime }, total: total };
this._suiteResults.total += total;

if (this._client?.didRunTest)
await this._client.didRunTest(this._suite, test);
Expand Down

0 comments on commit 1552769

Please sign in to comment.