Skip to content

Instantly share code, notes, and snippets.

@limistah
Forked from mmalecki/nextTick.js
Created May 1, 2020 08:05
Show Gist options
  • Save limistah/0c2dd2c33c851548e8d7be0d482676a1 to your computer and use it in GitHub Desktop.
Save limistah/0c2dd2c33c851548e8d7be0d482676a1 to your computer and use it in GitHub Desktop.
process.nextTick vs setTimeout(fn, 0)
for (var i = 0; i < 1024 * 1024; i++) {
process.nextTick(function () { Math.sqrt(i) } )
}

Results

Intel i7 890 @ 2.93 GHz x64, node compiled with -march=native -mtune=native:

$ time node nextTick.js 

real	0m0.344s
user	0m0.276s
sys 	0m0.067s

$ time node setTimeout.js 

real	0m9.125s
user	0m8.707s
sys 	0m0.410s

Feel free to fork and add your results!

for (var i = 0; i < 1024 * 1024; i++) {
setTimeout(function () { Math.sqrt(i) }, 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment