Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions resources/shared/benchmark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export class BenchmarkStep {
this.run = run;
}

async runAndRecordStep(params, suite, step, callback) {
const stepRunner = new StepRunner(null, null, params, suite, step, callback);
async runAndRecordStep(params, suite, step) {
const stepRunner = new StepRunner(null, null, params, suite, step);
const result = await stepRunner.runStep();
return result;
}
}

export class AsyncBenchmarkStep extends BenchmarkStep {
async runAndRecord(params, suite, test, callback) {
const testRunner = new AsyncStepRunner(null, null, params, suite, test, callback);
const result = await testRunner.runTest();
async runAndRecordStep(params, suite, step) {
const stepRunner = new AsyncStepRunner(null, null, params, suite, step);
const result = await stepRunner.runStep();
return result;
}
}
Expand All @@ -47,16 +47,6 @@ export class BenchmarkSuite {
console.assert(this.type in BENCHMARK_SUITE_TYPE, "Invalid Type", this.type);
}

record(_step, syncTime, asyncTime) {
const total = syncTime + asyncTime;
const results = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};

return results;
}

async runAndRecordSuite(params, onProgress) {
const measuredValues = {
tests: {},
Expand All @@ -69,10 +59,18 @@ export class BenchmarkSuite {
performance.mark(suiteStartLabel);

for (const step of this.steps) {
const result = await step.runAndRecordStep(params, this, step, this.record);
console.assert(result, "Missing test return value", step);
measuredValues.tests[step.name] = result;
measuredValues.total += result.total;
const rawResult = await step.runAndRecordStep(params, this, step);
console.assert(rawResult, "Missing test return value", step);
const { syncTime, asyncTime } = rawResult;
const total = syncTime + asyncTime;
const result = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};
if (!step.ignoreResult) {
measuredValues.tests[step.name] = result;
measuredValues.total += total;
}
onProgress?.(step.name);
}

Expand Down
15 changes: 4 additions & 11 deletions resources/shared/step-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ export class StepRunner {
#params;
#suite;
#step;
#callback;
#type;

constructor(frame, page, params, suite, step, callback, type) {
constructor(frame, page, params, suite, step, type) {
this.#suite = suite;
this.#step = step;
this.#params = params;
this.#callback = callback;
this.#page = page;
this.#frame = frame;
this.#type = type;
Expand Down Expand Up @@ -89,20 +87,15 @@ export class StepRunner {
performance.measure(`${suiteName}.${stepName}-async`, syncEndLabel, asyncEndLabel);
};

const report = () => this.#callback(this.#step, syncTime, asyncTime);
const schedulerType = this.#suite.type === "async" || this.#params.useAsyncSteps ? "async" : this.#params.measurementMethod;
const schedulerClass = STEP_SCHEDULER_LOOKUP[schedulerType];
const scheduler = new schedulerClass(runSync, measureAsync, report, this.#params);

return scheduler.start();
const scheduler = new schedulerClass(runSync, measureAsync, this.#params);
await scheduler.start();
return { syncTime, asyncTime };
}
}

export class AsyncStepRunner extends StepRunner {
constructor(frame, page, params, suite, step, callback, type) {
super(frame, page, params, suite, step, callback, type);
}

async _runSyncStep(step, page) {
await step.run(page);
}
Expand Down
13 changes: 3 additions & 10 deletions resources/shared/step-scheduler.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class StepScheduler {
constructor(syncCallback, asyncCallback, reportCallback, params) {
constructor(syncCallback, asyncCallback, params) {
this._syncCallback = syncCallback;
this._asyncCallback = asyncCallback;
this._reportCallback = reportCallback;
this._params = params;
}

Expand All @@ -22,10 +21,7 @@ class RAFStepScheduler extends StepScheduler {
requestAnimationFrame(() => {
setTimeout(() => {
this._asyncCallback();
setTimeout(async () => {
const result = await this._reportCallback();
resolve(result);
}, 0);
setTimeout(resolve, 0);
}, 0);
});
}
Expand All @@ -43,10 +39,7 @@ class AsyncRAFStepScheduler extends StepScheduler {
return;

this._asyncCallback();
setTimeout(async () => {
const results = await this._reportCallback();
resolve(results);
}, 0);
setTimeout(resolve, 0);
};

requestAnimationFrame(async () => {
Expand Down
9 changes: 5 additions & 4 deletions resources/suite-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ export class SuiteRunner {

const stepRunnerType = this.#suite.type ?? this.params.useAsyncSteps ? "async" : "default";
const stepRunnerClass = STEP_RUNNER_LOOKUP[stepRunnerType];
const stepRunner = new stepRunnerClass(this.#frame, this.#page, this.#params, this.#suite, step, this._recordTestResults, stepRunnerType);
await stepRunner.runStep();
const stepRunner = new stepRunnerClass(this.#frame, this.#page, this.#params, this.#suite, step, stepRunnerType);
let { syncTime, asyncTime } = await stepRunner.runStep();
this._recordTestResults(step, syncTime, asyncTime);
}
performance.mark(suiteEndLabel);

Expand Down Expand Up @@ -123,7 +124,7 @@ export class SuiteRunner {
});
}

_recordTestResults = async (step, syncTime, asyncTime) => {
async _recordTestResults(step, syncTime, asyncTime) {
// Skip reporting updates for the warmup suite.
if (this.#suite === WarmupSuite)
return;
Expand All @@ -135,7 +136,7 @@ export class SuiteRunner {
};
this.#suiteResults.prepare = this.#prepareTime;
this.#suiteResults.total = total;
};
}

async _updateClient(suite = this.#suite) {
if (this.#client?.didFinishSuite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class BenchmarkStep {
this.ignoreResult = ignoreResult;
}

async runAndRecord(params, suite, test, callback) {
async runAndRecord(params, suite, test) {
const StepRunnerClass = params.useAsyncSteps ? AsyncStepRunner : StepRunner;
const type = params.useAsyncSteps ? "async" : "sync";
const stepRunner = new StepRunnerClass(null, null, params, suite, test, callback, type);
const stepRunner = new StepRunnerClass(null, null, params, suite, test, type);
const result = await stepRunner.runStep();
return result;
}
Expand All @@ -34,15 +34,6 @@ export class BenchmarkSuite {
this.tests = tests;
}

record(_test, syncTime, asyncTime) {
const total = syncTime + asyncTime;
const results = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};

return results;
}

async runAndRecord(params, onProgress) {
const measuredValues = {
Expand All @@ -55,10 +46,15 @@ export class BenchmarkSuite {
performance.mark(suiteStartLabel);

for (const test of this.tests) {
const result = await test.runAndRecord(params, this, test, this.record);
const { syncTime, asyncTime } = await test.runAndRecord(params, this, test);
const total = syncTime + asyncTime;
const result = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};
if (!test.ignoreResult) {
measuredValues.tests[test.name] = result;
measuredValues.total += result.total;
measuredValues.total += total;
}
onProgress?.(test.name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ export class StepRunner {
#params;
#suite;
#step;
#callback;
#type;

constructor(frame, page, params, suite, step, callback, type) {
constructor(frame, page, params, suite, step, type) {
this.#suite = suite;
this.#step = step;
this.#params = params;
this.#callback = callback;
this.#page = page;
this.#frame = frame;
this.#type = type;
Expand Down Expand Up @@ -89,20 +87,15 @@ export class StepRunner {
performance.measure(`${suiteName}.${stepName}-async`, syncEndLabel, asyncEndLabel);
};

const report = () => this.#callback(this.#step, syncTime, asyncTime);
const schedulerType = this.#suite.type === "async" || this.#params.useAsyncSteps ? "async" : this.#params.measurementMethod;
const schedulerClass = STEP_SCHEDULER_LOOKUP[schedulerType];
const scheduler = new schedulerClass(runSync, measureAsync, report, this.#params);

return scheduler.start();
const scheduler = new schedulerClass(runSync, measureAsync, this.#params);
await scheduler.start();
return { syncTime, asyncTime };
}
}

export class AsyncStepRunner extends StepRunner {
constructor(frame, page, params, suite, step, callback, type) {
super(frame, page, params, suite, step, callback, type);
}

async _runSyncStep(step, page) {
await step.run(page);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class StepScheduler {
constructor(syncCallback, asyncCallback, reportCallback, params) {
constructor(syncCallback, asyncCallback, params) {
this._syncCallback = syncCallback;
this._asyncCallback = asyncCallback;
this._reportCallback = reportCallback;
this._params = params;
}

Expand All @@ -22,10 +21,7 @@ class RAFStepScheduler extends StepScheduler {
requestAnimationFrame(() => {
setTimeout(() => {
this._asyncCallback();
setTimeout(async () => {
const result = await this._reportCallback();
resolve(result);
}, 0);
setTimeout(resolve, 0);
}, 0);
});
}
Expand All @@ -43,10 +39,7 @@ class AsyncRAFStepScheduler extends StepScheduler {
return;

this._asyncCallback();
setTimeout(async () => {
const results = await this._reportCallback();
resolve(results);
}, 0);
setTimeout(resolve, 0);
};

requestAnimationFrame(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class BenchmarkStep {
this.ignoreResult = ignoreResult;
}

async runAndRecord(params, suite, test, callback) {
async runAndRecord(params, suite, test) {
const StepRunnerClass = params.useAsyncSteps ? AsyncStepRunner : StepRunner;
const type = params.useAsyncSteps ? "async" : "sync";
const stepRunner = new StepRunnerClass(null, null, params, suite, test, callback, type);
const stepRunner = new StepRunnerClass(null, null, params, suite, test, type);
const result = await stepRunner.runStep();
return result;
}
Expand All @@ -34,16 +34,6 @@ export class BenchmarkSuite {
this.tests = tests;
}

record(_test, syncTime, asyncTime) {
const total = syncTime + asyncTime;
const results = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};

return results;
}

async runAndRecord(params, onProgress) {
const measuredValues = {
tests: {},
Expand All @@ -55,10 +45,15 @@ export class BenchmarkSuite {
performance.mark(suiteStartLabel);

for (const test of this.tests) {
const result = await test.runAndRecord(params, this, test, this.record);
const { syncTime, asyncTime } = await test.runAndRecord(params, this, test);
const total = syncTime + asyncTime;
const result = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};
if (!test.ignoreResult) {
measuredValues.tests[test.name] = result;
measuredValues.total += result.total;
measuredValues.total += total;
}
onProgress?.(test.name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ export class BenchmarkStep {
this.run = run;
}

async runAndRecordStep(params, suite, step, callback) {
const stepRunner = new StepRunner(null, null, params, suite, step, callback);
async runAndRecordStep(params, suite, step) {
const stepRunner = new StepRunner(null, null, params, suite, step);
const result = await stepRunner.runStep();
return result;
}
}

export class AsyncBenchmarkStep extends BenchmarkStep {
async runAndRecord(params, suite, test, callback) {
const testRunner = new AsyncStepRunner(null, null, params, suite, test, callback);
const result = await testRunner.runTest();
async runAndRecordStep(params, suite, step) {
const stepRunner = new AsyncStepRunner(null, null, params, suite, step);
const result = await stepRunner.runStep();
return result;
}
}
Expand All @@ -47,16 +47,6 @@ export class BenchmarkSuite {
console.assert(this.type in BENCHMARK_SUITE_TYPE, "Invalid Type", this.type);
}

record(_step, syncTime, asyncTime) {
const total = syncTime + asyncTime;
const results = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};

return results;
}

async runAndRecordSuite(params, onProgress) {
const measuredValues = {
tests: {},
Expand All @@ -69,10 +59,18 @@ export class BenchmarkSuite {
performance.mark(suiteStartLabel);

for (const step of this.steps) {
const result = await step.runAndRecordStep(params, this, step, this.record);
console.assert(result, "Missing test return value", step);
measuredValues.tests[step.name] = result;
measuredValues.total += result.total;
const rawResult = await step.runAndRecordStep(params, this, step);
console.assert(rawResult, "Missing test return value", step);
const { syncTime, asyncTime } = rawResult;
const total = syncTime + asyncTime;
const result = {
tests: { Sync: syncTime, Async: asyncTime },
total: total,
};
if (!step.ignoreResult) {
measuredValues.tests[step.name] = result;
measuredValues.total += total;
}
onProgress?.(step.name);
}

Expand Down
Loading
Loading