I was writting a benchmark utility when I found the isaacs node-bench 
module and found this code:

var nt_ = typeof setImmediate === 'function' ? setImmediate : process.nextTick
> var ntN = 0
> function nt(fn) {
>   if (ntN++ < 100)
>     return process.nextTick(fn)
>   nt_(fn)
>   ntN = 0
> }
>
>
If you rewrite in a more cleaner way...


var async = (function (){
>     var i = 0;
>     return function (fn){
>         if (i++ < 100){
>             process.nextTick (fn);
>         }else{
>             setImmediate (fn);
>             i = 0;
>         }
>     }})();
> async (function (){
>     //Asynchronous code});
>
>
This code permits to use nextTick without reaching the call stack error.

While I was writting my benchmark module I noticed 2 things:

- Recursively calls to setImmediate produces inconsistent values: 100, then 
150, then 70, etc. when I should get 100, 105, 101, 95, etc. With nextTick 
(using the above function) the results are pretty consistent. Why?
- setImmediate is much more slower than nextTick, aproximately 10 times 
slower. Why?

little spam: node-speedy <https://github.com/gagle/node-speedy>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to