Last active
November 13, 2015 10:43
-
-
Save dmitryshimkin/8a37bea1794228528fd2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function () { | |
| var start; | |
| var isRunning = false; | |
| var frames = 0; | |
| var intervalId; | |
| var entries = []; | |
| function onFrame () { | |
| if (isRunning) { | |
| window.requestAnimationFrame(onFrame); | |
| frames = frames + 1; | |
| } | |
| } | |
| window.FPS = { | |
| getFPS: function () { | |
| var totalTime = (Date.now() - start) / 1000; | |
| return frames / totalTime; | |
| }, | |
| printResults: function () { | |
| entries.forEach(function (entry) { | |
| if (entry < 59) { | |
| console.warn(entry); | |
| } else { | |
| console.info(entry); | |
| } | |
| }); | |
| }, | |
| reset: function () { | |
| start = Date.now(); | |
| frames = 0; | |
| }, | |
| start: function () { | |
| start = Date.now(); | |
| isRunning = true; | |
| window.requestAnimationFrame(onFrame); | |
| }, | |
| stop: function () { | |
| start = null; | |
| isRunning = false; | |
| }, | |
| startTrack: function () { | |
| this.reset(); | |
| this.start(); | |
| intervalId = setInterval(function () { | |
| entries.push(this.getFPS()); | |
| this.reset(); | |
| }.bind(this), 1000); | |
| }, | |
| stopTrack: function () { | |
| this.stop(); | |
| clearInterval(intervalId); | |
| } | |
| } | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment