Skip to content

Instantly share code, notes, and snippets.

@riccardolardi
Created January 8, 2019 15:09
Show Gist options
  • Save riccardolardi/37fe77eecd26fcd971aecdb13697540f to your computer and use it in GitHub Desktop.
Save riccardolardi/37fe77eecd26fcd971aecdb13697540f to your computer and use it in GitHub Desktop.
const {performance} = require('perf_hooks')
let lastTs, newTs
const desiredFps = 30.0
const interval = () => {
lastTs = newTs
newTs = performance.now()
const err = newTs - lastTs - 1000.0 / desiredFps
const newDelay = 1000.0 / desiredFps - err
setTimeout(interval, newDelay)
}
interval()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment