diff --git a/resources/benchmark-runner.mjs b/resources/benchmark-runner.mjs index edb825af5..b9741199d 100644 --- a/resources/benchmark-runner.mjs +++ b/resources/benchmark-runner.mjs @@ -1,5 +1,6 @@ import { Metric } from "./metric.mjs"; import { params } from "./params.mjs"; +import { TEST_INVOKER_LOOKUP } from "./test-invoker.mjs"; const performance = globalThis.performance; @@ -266,61 +267,6 @@ const WarmupSuite = { ], }; -class TestInvoker { - constructor(syncCallback, asyncCallback, reportCallback) { - this._syncCallback = syncCallback; - this._asyncCallback = asyncCallback; - this._reportCallback = reportCallback; - } -} - -class TimerTestInvoker extends TestInvoker { - start() { - return new Promise((resolve) => { - setTimeout(() => { - this._syncCallback(); - setTimeout(() => { - this._asyncCallback(); - requestAnimationFrame(async () => { - await this._reportCallback(); - resolve(); - }); - }, 0); - }, params.waitBeforeSync); - }); - } -} - -class RAFTestInvoker extends TestInvoker { - start() { - return new Promise((resolve) => { - if (params.waitBeforeSync) - setTimeout(() => this._scheduleCallbacks(resolve), params.waitBeforeSync); - else - this._scheduleCallbacks(resolve); - }); - } - - _scheduleCallbacks(resolve) { - requestAnimationFrame(() => this._syncCallback()); - requestAnimationFrame(() => { - setTimeout(() => { - this._asyncCallback(); - setTimeout(async () => { - await this._reportCallback(); - resolve(); - }, 0); - }, 0); - }); - } -} - -const TEST_INVOKER_LOOKUP = { - __proto__: null, - timer: TimerTestInvoker, - raf: RAFTestInvoker, -}; - // https://stackoverflow.com/a/47593316 function seededHashRandomNumberGenerator(a) { return function () { @@ -658,7 +604,7 @@ export class SuiteRunner { const report = () => this._recordTestResults(test, syncTime, asyncTime); const invokerClass = TEST_INVOKER_LOOKUP[params.measurementMethod]; - const invoker = new invokerClass(runSync, measureAsync, report); + const invoker = new invokerClass(runSync, measureAsync, report, params); return invoker.start(); } diff --git a/resources/test-invoker.mjs b/resources/test-invoker.mjs new file mode 100644 index 000000000..672c69ae0 --- /dev/null +++ b/resources/test-invoker.mjs @@ -0,0 +1,55 @@ +class TestInvoker { + constructor(syncCallback, asyncCallback, reportCallback, params) { + this._syncCallback = syncCallback; + this._asyncCallback = asyncCallback; + this._reportCallback = reportCallback; + this._params = params; + } +} + +export class TimerTestInvoker extends TestInvoker { + start() { + return new Promise((resolve) => { + setTimeout(() => { + this._syncCallback(); + setTimeout(() => { + this._asyncCallback(); + requestAnimationFrame(async () => { + await this._reportCallback(); + resolve(); + }); + }, 0); + }, this._params.waitBeforeSync); + }); + } +} + +export class RAFTestInvoker extends TestInvoker { + start() { + return new Promise((resolve) => { + if (this._params.waitBeforeSync) + setTimeout(() => this._scheduleCallbacks(resolve), this._params.waitBeforeSync); + else + this._scheduleCallbacks(resolve); + }); + } + + _scheduleCallbacks(resolve) { + requestAnimationFrame(() => this._syncCallback()); + requestAnimationFrame(() => { + setTimeout(() => { + this._asyncCallback(); + setTimeout(async () => { + await this._reportCallback(); + resolve(); + }, 0); + }, 0); + }); + } +} + +export const TEST_INVOKER_LOOKUP = { + __proto__: null, + timer: TimerTestInvoker, + raf: RAFTestInvoker, +};