Last active
December 13, 2019 10:57
-
-
Save AlexanderShushunov/6e0702383d7494db45c44c31f2ffb72b to your computer and use it in GitHub Desktop.
Snippet to measure operation per second
This file contains 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 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