Skip to content

Instantly share code, notes, and snippets.

@Mukundhan-I2I
Created December 24, 2019 16:00
Show Gist options
  • Save Mukundhan-I2I/f12a774214c0bfe2167a966ca80f983e to your computer and use it in GitHub Desktop.
Save Mukundhan-I2I/f12a774214c0bfe2167a966ca80f983e to your computer and use it in GitHub Desktop.
node process.next tick unveiled
const start = Date.now();
let count = 0;
const tick = process.nextTick;
const log = () => {
count += 1;
if((Date.now() - start) !== 1000) {
tick(log);
} else {
console.log('ticks per second', count);
}
}
tick(log);
// 1 51,68,811
// 2 36,57,219
// 3 31,86,158
// 4 25,31,861
// 5 22,48,128
@Mukundhan-I2I
Copy link
Author

const start = Date.now();
let count = 0;
const tick = process.nextTick;
const log = () => {
count += 1;
// Date.now()
// Date.now()
// Date.now()
// Date.now()
// Date.now()
if((Date.now() - start) !== 1000) {
tick(log);
} else {
console.log('ticks per second', count);
}
}
tick(log);
// Date.now() impact!!
// 0 ?????????
// 1 51,68,811
// 2 36,57,219
// 3 31,86,158
// 4 25,31,861
// 5 22,48,128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment