Skip to content

Commit 24b094d

Browse files
authored
Use performance.measure api instead of manually tracking with performance.now() (#79)
1 parent d8bea6b commit 24b094d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

resources/benchmark-runner.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export class BenchmarkRunner {
237237

238238
const syncTime = syncEndTime - syncStartTime;
239239

240+
performance.mark(`${suite.name}.${test.name}-async-start`);
240241
const asyncStartTime = performance.now();
241242
setTimeout(() => {
242243
// Some browsers don't immediately update the layout for paint.
@@ -246,6 +247,8 @@ export class BenchmarkRunner {
246247
const asyncTime = asyncEndTime - asyncStartTime;
247248
this._frame.contentWindow._unusedHeightValue = height; // Prevent dead code elimination.
248249
performance.mark(`${suite.name}.${test.name}-async-end`);
250+
performance.measure(`${suite.name}.${test.name}-sync`, `${suite.name}.${test.name}-start`, `${suite.name}.${test.name}-sync-end`);
251+
performance.measure(`${suite.name}.${test.name}-async`, `${suite.name}.${test.name}-async-start`, `${suite.name}.${test.name}-async-end`);
249252
window.requestAnimationFrame(() => {
250253
callback(syncTime, asyncTime, height);
251254
});

tests/benchmark-runner-tests.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ describe("BenchmarkRunner", () => {
211211
it("should write performance marks at the start and end of the test with the correct test name", () => {
212212
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-start");
213213
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-sync-end");
214+
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-async-start");
214215
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-async-end");
215-
assert.calledThrice(peformanceMarkSpy);
216+
expect(peformanceMarkSpy.callCount).to.equal(4);
216217
});
217218

218219
it("should run the test", () => {

0 commit comments

Comments
 (0)