Skip to content

Instantly share code, notes, and snippets.

@dm03514
Created February 28, 2019 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dm03514/69bdf6451b49ca1f63b4326c389a59b8 to your computer and use it in GitHub Desktop.
Save dm03514/69bdf6451b49ca1f63b4326c389a59b8 to your computer and use it in GitHub Desktop.
Test to calculate rate of operations
// 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