Created
December 7, 2018 05:50
-
-
Save Lxxyx/f1786482759fc71369fa9d979dd624ec to your computer and use it in GitHub Desktop.
fps
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 detectFpsInPeriod(options) { | |
const now = () => performance.now() | |
const startTime = now() | |
let lastOutputTime = now(); | |
let frameCount = 0; | |
const fpsResult = [] | |
let stoped = false; | |
function getFps() { | |
frameCount++; | |
let currentFrame = now() | |
if (currentFrame - lastOutputTime >= 1000) { | |
const fps = frameCount | |
fpsResult.push({ | |
fps | |
}) | |
frameCount = 0; | |
lastOutputTime = currentFrame; | |
} | |
if (!stoped) { | |
requestAnimationFrame(getFps) | |
} | |
} | |
setTimeout(() => { | |
options.callback && options.callback(fpsResult, startTime, now()) | |
stoped = true | |
}, options.seconds * 1000); | |
requestAnimationFrame(getFps) | |
} | |
function autoScrollInSeconds(seconds) { | |
const now = () => performance.now() | |
const element = document.querySelector('#_current_nested_child') | |
const startTime = now() | |
const endTime = startTime + seconds * 1000 | |
function scrollDown() { | |
element.scrollTop += 8 | |
if (now() < endTime) { | |
requestAnimationFrame(scrollDown) | |
} | |
} | |
requestAnimationFrame(scrollDown) | |
} | |
var seconds = 240 | |
detectFpsInPeriod({ | |
seconds: seconds, | |
callback: (result, startTime, endTime) => { | |
console.log(JSON.stringify(result)) | |
// console.log('FPS TimeInfo', startTime, endTime) | |
}, | |
frequency: 250 | |
}) | |
autoScrollInSeconds(seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment