Created
December 24, 2019 16:00
-
-
Save Mukundhan-I2I/f12a774214c0bfe2167a966ca80f983e to your computer and use it in GitHub Desktop.
node process.next tick unveiled
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
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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