Skip to content

Commit f1c7edb

Browse files
shallawasmfr
authored andcommitted
Frame rate detection on MotionMark occasionally sees older devices as 90 fps instead of 60
#50 rdar://127012351 To get the target frame rate we sample 300 rAFs and we get the average of their frame rates. We calculate the average incrementally using some sort of exponential decay. The average starts very small but keeps increasing until it reaches the actual target frame rate and it is supposed to stay unchanged much. Then we compare the final average rate with predefined frame rates and get the closest one. The purpose of this incremental calculation was to show the target frame rate being calculated in the detectionProgressElement in the developer page. In addition to having the incremental average very small for more than 100 frames, the bigger problem is this incremental average calculation gives more weight to the last frame. And if it is considerably large for any reason, the final average will be wildly inaccurate. The fix is to simplify the calculations: 1. For count == 0: The firstTimeStamp will be recorded and and we won't update the detectionProgressElement. 2. For count > 0: averageFrameLength = (timestamp - firstTimeStamp) / count; averageFrameRate = 1000 / averageFrameLength;
1 parent f3034d6 commit f1c7edb

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

MotionMark/resources/runner/motionmark.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,15 @@ window.benchmarkController = {
558558
determineFrameRate: function(detectionProgressElement)
559559
{
560560
return new Promise((resolve, reject) => {
561-
let last = 0;
562-
let average = 0;
561+
let firstTimestamp;
563562
let count = 0;
564563

565-
const finish = function()
564+
const averageFrameRate = function(timestamp)
565+
{
566+
return 1000. / ((timestamp - firstTimestamp) / count);
567+
}
568+
569+
const finish = function(average)
566570
{
567571
const commonFrameRates = [15, 30, 45, 60, 90, 120, 144];
568572
const distanceFromFrameRates = commonFrameRates.map(rate => {
@@ -585,16 +589,17 @@ window.benchmarkController = {
585589

586590
const tick = function(timestamp)
587591
{
588-
average -= average / 30;
589-
average += 1000. / (timestamp - last) / 30;
590-
if (detectionProgressElement)
591-
detectionProgressElement.textContent = Math.round(average);
592-
last = timestamp;
592+
if (!firstTimestamp)
593+
firstTimestamp = timestamp;
594+
else if (detectionProgressElement)
595+
detectionProgressElement.textContent = Math.round(averageFrameRate(timestamp));
596+
593597
count++;
598+
594599
if (count < 300)
595600
requestAnimationFrame(tick);
596601
else
597-
finish();
602+
finish(averageFrameRate(timestamp));
598603
}
599604

600605
requestAnimationFrame(tick);

0 commit comments

Comments
 (0)