Khan / Khan/live-editor

frameRate is not setting the correct frame rate

Open
#627 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
776
Forks
180
PR merge metrics
No merged PRs in 30d

Description

This code calculates the frame rate.
```
var frames = 180; // set it below the maximum frame rate
frameRate(frames);
var data = [millis()];
draw = function() {
println(1000*data.length/(millis()-data[0])); // Frame rate taking the last 100 frames into account
println(1000/floor(1000/frames)); // Calculated frame rate according to theory
//println((millis()-data[0])/data.length);
data.push(millis());
if (data.length>100) {
data = data.slice(1);
}
};
```
However, the actual frame rate is close to the 1000/floor(1000/frameRate) when you run this code.

I suspect it might be something to do with setInterval or setTimeout not allowing non-integer values, and rounding the interval downwards.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the provided frameRate(180) example in the browser-based live editor and inspect the frameRate implementation, especially its setInterval or setTimeout scheduling. Confirm the measured rate and the calculated 1000/floor(1000/frameRate) value, then consider the issue done when the requested frame rate is applied without the observed downward rounding.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.