Skip to content

Instantly share code, notes, and snippets.

@xaviervia
Created February 24, 2017 14:01
Show Gist options
  • Save xaviervia/c3ef5a1e470fac3d60b7a172c2736b1e to your computer and use it in GitHub Desktop.
Save xaviervia/c3ef5a1e470fac3d60b7a172c2736b1e to your computer and use it in GitHub Desktop.
window.profileSTandRAF = () => {
let end = false
let setTimeoutCount = 0
let requestAnimationFrameCount = 0
setTimeout(() => { end = true }, 2000)
const setTimeoutLoop = () => {
setTimeoutCount = setTimeoutCount + 1
if (!end) {
console.log('setTimeout count', setTimeoutCount)
setTimeout(setTimeoutLoop)
} else {
console.log('setTimeout total', setTimeoutCount)
}
}
const requestAnimationFrameLoop = () => {
requestAnimationFrameCount = requestAnimationFrameCount + 1
if (!end) {
console.log('requestAnimationFrame count', requestAnimationFrameCount)
requestAnimationFrame(requestAnimationFrameLoop)
} else {
console.log('requestAnimationFrame total', requestAnimationFrameCount)
}
}
setTimeout(() => {
setTimeoutLoop()
requestAnimationFrameLoop()
}, 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment