Skip to content

Commit

Permalink
Use performance.measure api instead of manually tracking with perform…
Browse files Browse the repository at this point in the history
…ance.now() (#79)
  • Loading branch information
bgrins authored Feb 27, 2023
1 parent d8bea6b commit 24b094d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions resources/benchmark-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export class BenchmarkRunner {

const syncTime = syncEndTime - syncStartTime;

performance.mark(`${suite.name}.${test.name}-async-start`);
const asyncStartTime = performance.now();
setTimeout(() => {
// Some browsers don't immediately update the layout for paint.
Expand All @@ -246,6 +247,8 @@ export class BenchmarkRunner {
const asyncTime = asyncEndTime - asyncStartTime;
this._frame.contentWindow._unusedHeightValue = height; // Prevent dead code elimination.
performance.mark(`${suite.name}.${test.name}-async-end`);
performance.measure(`${suite.name}.${test.name}-sync`, `${suite.name}.${test.name}-start`, `${suite.name}.${test.name}-sync-end`);
performance.measure(`${suite.name}.${test.name}-async`, `${suite.name}.${test.name}-async-start`, `${suite.name}.${test.name}-async-end`);
window.requestAnimationFrame(() => {
callback(syncTime, asyncTime, height);
});
Expand Down
3 changes: 2 additions & 1 deletion tests/benchmark-runner-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ describe("BenchmarkRunner", () => {
it("should write performance marks at the start and end of the test with the correct test name", () => {
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-start");
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-sync-end");
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-async-start");
assert.calledWith(peformanceMarkSpy, "Suite 1.Test 1-async-end");
assert.calledThrice(peformanceMarkSpy);
expect(peformanceMarkSpy.callCount).to.equal(4);
});

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

0 comments on commit 24b094d

Please sign in to comment.