Skip to content

Instantly share code, notes, and snippets.

@AlexanderShushunov
Last active December 13, 2019 10:57
Show Gist options
  • Save AlexanderShushunov/6e0702383d7494db45c44c31f2ffb72b to your computer and use it in GitHub Desktop.
Save AlexanderShushunov/6e0702383d7494db45c44c31f2ffb72b to your computer and use it in GitHub Desktop.
Snippet to measure operation per second
function operationPerSecond () {
let lastNotifyTime = Date.now()
let operationCount = 0
return () => {
operationCount++
if (Date.now() - lastNotifyTime > 1000) {
console.log('opp per sec:', operationCount)
operationCount = 0
lastNotifyTime = Date.now()
}
}
}
const tick = operationPerSecond()
function varyFrequentlyOpperation () {
// some code
tick()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment