Skip to content

Commit 1552769

Browse files
authored
Add local results variable to SuiteRunner (#445)
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.
1 parent 04cfe65 commit 1552769

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

resources/benchmark-runner.mjs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,11 @@ export class BenchmarkRunner {
543543
export class SuiteRunner {
544544
constructor(measuredValues, frame, page, client, suite) {
545545
// FIXME: Create SuiteRunner-local measuredValues.
546+
this._suiteResults = measuredValues.tests[suite.name];
547+
if (!this._suiteResults) {
548+
this._suiteResults = { tests: {}, total: 0 };
549+
measuredValues.tests[suite.name] = this._suiteResults;
550+
}
546551
this._measuredValues = measuredValues;
547552
this._frame = frame;
548553
this._page = page;
@@ -579,17 +584,16 @@ export class SuiteRunner {
579584
performance.mark(suiteEndLabel);
580585

581586
performance.measure(`suite-${suiteName}`, suiteStartLabel, suiteEndLabel);
582-
this._validateSuiteTotal(suiteName);
587+
this._validateSuiteTotal();
583588
}
584589

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

595599
async _loadFrame() {
@@ -663,12 +667,10 @@ export class SuiteRunner {
663667
// Skip reporting updates for the warmup suite.
664668
if (this._suite === WarmupSuite)
665669
return;
666-
const suiteName = this._suite.name;
667-
const suiteResults = this._measuredValues.tests[suiteName] || { tests: {}, total: 0 };
670+
668671
const total = syncTime + asyncTime;
669-
this._measuredValues.tests[suiteName] = suiteResults;
670-
suiteResults.tests[test.name] = { tests: { Sync: syncTime, Async: asyncTime }, total: total };
671-
suiteResults.total += total;
672+
this._suiteResults.tests[test.name] = { tests: { Sync: syncTime, Async: asyncTime }, total: total };
673+
this._suiteResults.total += total;
672674

673675
if (this._client?.didRunTest)
674676
await this._client.didRunTest(this._suite, test);

0 commit comments

Comments
 (0)