Calculate FPS in Canvas using requestAnimationFrame

前端 未结 10 2252
滥情空心
滥情空心 2020-11-30 00:31

How could I calculate the FPS of a canvas game application? I\'ve seen some examples, but none of them use requestAnimationFrame, and im not sure how to apply their solution

10条回答
  •  臣服心动
    2020-11-30 01:13

    Chrome has a built-in fps counter: https://developer.chrome.com/devtools/docs/rendering-settings

    Just open the dev-console (F12), open the drawer (Esc), and add the "Rendering" tab.

    Here, you can activate the FPS-Meter overlay to see the current framerate (incl. a nice graph), as well as GPU memory consumption.

    Cross-browser solution: You can get a similar overlay with the JavaScript library stat.js: https://github.com/mrdoob/stats.js/

    It also provides a nice overlay for the framerate (incl. graph) and is very easy to use.

    When comparing the results from stats.js and the chrome dev tools, both show the exact same measurements. So you can trust that library to actually do the correct thing.

提交回复
热议问题