Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3975906
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:44:29+00:00 2026-05-20T04:44:29+00:00

I know a few questions have been asked like this one before, such as

  • 0

I know a few questions have been asked like this one before, such as this: Check FPS in JS? – which did work to some degree, I was able to find out how long each loop took to complete.

What I am looking for though is something more readable and controllable. I want to be able to set the refresh rate for the FPS counter to make it slow so it is human readable or as fast as the application can run, so I can use it on some kind of speedometer.

Anyway so here is the code I have right now:

var lastLoop = new Date().getTime();

function updateStage()
{   
    clearCanvas();
    updateStageObjects();
    drawStageObjects();     

    var thisLoop = new Date().getTime(); 
    var fps = (thisLoop - lastLoop);

    $('#details').html(fps);

    lastLoop = thisLoop;
    iteration = setTimeout(updateStage, 1);
}
  1. Am I right to be setting the setTimeout function to a speed of 1 millisecond? I was thinking this will just make it loop as fast as it possibly can.

  2. Should I count every 100 frames or so, find out how many milliseconds it took to run 100 frames then make a calculation to find out how many frames it would have done if the milliseconds were 1000? What would this calculation be?

  3. To make the result more accurate I am guessing I need to display averages as one frame can vary a significant amount, how should I do this?

Any tips are greatly appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T04:44:29+00:00Added an answer on May 20, 2026 at 4:44 am
    1. Note that the faster you update your output, the more you will affect your measurement. Although minimal, I try to update my fps output once per second or less unless it’s necessary to go faster.

    2. I like to have a low-pass filter on my results so that a temporary hiccup doesn’t affect the values too strongly. This is easier to compute and write than a moving average, and doesn’t have the problem of an overall average where your ‘current’ readings are affected by total performance over the entire run (e.g. anomalous readings during startup).

    Put together, here’s how I usually measure FPS:

    var fps = 0, now, lastUpdate = (new Date)*1;
    
    // The higher this value, the less the FPS will be affected by quick changes
    // Setting this to 1 will show you the FPS of the last sampled frame only
    var fpsFilter = 50;
    
    function drawFrame(){
      // ... draw the frame ...
    
      var thisFrameFPS = 1000 / ((now=new Date) - lastUpdate);
      if (now!=lastUpdate){
        fps += (thisFrameFPS - fps) / fpsFilter;
        lastUpdate = now;
      }
    
      setTimeout( drawFrame, 1 );
    }
    
    var fpsOut = document.getElementById('fps');
    setInterval(function(){
      fpsOut.innerHTML = fps.toFixed(1) + "fps";
    }, 1000); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there have been a few threads on this before, but I have
I know this question has been asked before, but I feel it wasn't asked
I know that this question has been asked many times before in different guises
I'm a newbie to pgsql. I have few questionss on it: 1) I know
I know there are already a few questions regarding recommendations for C++ unit test
Know of any good libraries for this? I did some searches and didn't come
Ok, I've asked a few related questions here and only ended up with more
I know a few advanced ways, to change directories. pushd and popd (directory stack)
I know there are quite a few line count tools around. Is there something
Know of an OCAML/CAML IDE? Especially one that runs on Linux?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.