Created
February 28, 2019 17:58
-
-
Save dm03514/69bdf6451b49ca1f63b4326c389a59b8 to your computer and use it in GitHub Desktop.
Test to calculate rate of operations
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
// Averages the rate of operations over time since program started | |
const roundTo100ths = (num) => { | |
return Math.round(num * 100)/100; | |
}; | |
const start = new Date(); | |
let ticks = 0; | |
const timeout = process.env.INTERVAL_TIMEOUT_MS || 1000; | |
setInterval(() => { | |
ticks += 1; | |
if (ticks % 10 === 0) { | |
const diff = new Date() - start; | |
console.log(roundTo100ths(ticks / (diff / 1000)) + ' ops / second'); | |
} | |
}, timeout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment