Skip to content

Commit fa1560a

Browse files
authored
Use WakeLock (#491)
* Add WakeLock wrapper class around the web-api to keep the screen unlocked during benchmark runs * Use WakeLock.aquire() and WakeLock.release() in the benchmark runner
1 parent 275043e commit fa1560a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

resources/benchmark-runner.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,31 @@ function seededHashRandomNumberGenerator(a) {
277277
};
278278
}
279279

280+
class WakeLock {
281+
#wakeLockSentinel = undefined;
282+
async request() {
283+
if (!navigator.wakeLock)
284+
return;
285+
try {
286+
this.#wakeLockSentinel = await navigator.wakeLock.request("screen");
287+
} catch (err) {
288+
console.error(`${err.name}, ${err.message}`);
289+
}
290+
}
291+
292+
async release() {
293+
if (!this.#wakeLockSentinel)
294+
return;
295+
try {
296+
await this.#wakeLockSentinel.release();
297+
} catch (err) {
298+
console.error(`${err.name}, ${err.message}`);
299+
} finally {
300+
this.#wakeLockSentinel = undefined;
301+
}
302+
}
303+
}
304+
280305
export class BenchmarkRunner {
281306
constructor(suites, client) {
282307
this._suites = suites;
@@ -288,6 +313,7 @@ export class BenchmarkRunner {
288313
this._iterationCount = params.iterationCount;
289314
if (params.shuffleSeed !== "off")
290315
this._suiteOrderRandomNumberGenerator = seededHashRandomNumberGenerator(params.shuffleSeed);
316+
this._wakeLock = new WakeLock();
291317
}
292318

293319
async runMultipleIterations(iterationCount) {
@@ -350,6 +376,7 @@ export class BenchmarkRunner {
350376

351377
async _prepareAllSuites() {
352378
this._measuredValues = { tests: {}, total: 0, mean: NaN, geomean: NaN, score: NaN };
379+
await this._wakeLock.request();
353380

354381
const prepareStartLabel = "runner-prepare-start";
355382
const prepareEndLabel = "runner-prepare-end";
@@ -404,6 +431,7 @@ export class BenchmarkRunner {
404431
await this._finalize();
405432
performance.mark(finalizeEndLabel);
406433
performance.measure("runner-finalize", finalizeStartLabel, finalizeEndLabel);
434+
await this._wakeLock.release();
407435
}
408436

409437
async runSuite(suite) {

0 commit comments

Comments
 (0)