It took me 30 minutes staring on those 30 lines to understand Tims code ;-)

On Thu, Apr 12, 2012 at 11:32 PM, Bruno Jouhier <[email protected]> wrote:
> This pattern is fine for an async library helper but I doubt that people
> will be ready to write all their loops like this. I'm just thinking of the
> poor guy who's going to maintain this kind of code written by someone else.
>
>
>
> On Thursday, April 12, 2012 10:51:01 PM UTC+2, Tim Caswell wrote:
>>
>> Something productive came out of this thread.  I learned the name of the
>> trampoline technique and came up with a hand-written version of the
>> benchmark that's 4x faster than the streamline-js version.
>>
>> var count = 1000000;
>>
>> function bench(cb) {
>>   var total = 0;
>>   function loop(i) {
>>     var async;
>>     while (async !== true) {
>>       async = undefined;
>>       if (i === count) {
>>         cb(null, total);
>>       } else {
>>         load(__dirname + '/benchCallbacks.js', function(err, data) {
>>           if (err) return cb(err);
>>           total += data.length;
>>           if (async) {
>>             loop(i + 1);
>>           } else {
>>             async = false;
>>             i++;
>>           }
>>         });
>>       }
>>       if (async !== false) {
>>         async = true;
>>       }
>>     }
>>   }
>>   loop(0);
>> }
>>
>> Here are the speed numbers I'm getting on my machine with my new
>> trampoline style version asbenchCallbacks2.js.
>>
>> tim ~/gist-2362015 $ uname -a
>> Linux touchsmart 3.2.13-1-ARCH #1 SMP PREEMPT Sat Mar 24 09:10:39 CET 2012
>> x86_64 Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz GenuineIntel GNU/Linux
>> tim ~/gist-2362015 $ node benchCallbacks.js
>> hit=999999, missed=1, result=805000000
>> elapsed: 1297
>> tim ~/gist-2362015 $ _node benchStreamline
>> hit=999999, missed=1, result=805000000
>> elapsed: 1001
>> tim ~/gist-2362015 $ _node --fibers benchStreamline
>> hit=999999, missed=1, result=805000000
>> elapsed: 180
>> tim ~/gist-2362015 $ node benchCallbacks2.js
>> hit=999999, missed=1, result=805000000
>> elapsed: 308
>>
>>
>> Most applications won't notice the speed differences here, but I do
>> appreciate learning a new technique I'm sure to use in the future.
>>
>>
>> On Thu, Apr 12, 2012 at 3:36 PM, Mikeal Rogers <[email protected]>
>> wrote:
>>>
>>> How are we defining aggression?
>>>
>>> To me, the same 5 people offering the same answer on every related
>>> thread, representing nearly 60% of the traffic in that thread, for an
>>> approach that has by any available measure less than 2% of the community
>>> adopting it is **very aggressive**.
>>>
>>> -Mikeal
>>>
>>> On Apr 12, 2012, at April 12, 20121:33 PM, Marco Rogers wrote:
>>>
>>> Thanks for the backhanded support Axel :)
>>>
>>> Since when can we not make general statements once they've proven
>>> themselves to be generally true? How would we ever have best practices if
>>> nothing ever presented itself as best in the general sense?
>>>
>>> :Marco
>>>
>>> On Thursday, April 12, 2012 7:48:13 AM UTC-7, Axel Kittenberger wrote:
>>>>
>>>> > JavaScript is asynchronous, Node.js is asynchronous, everything feels
>>>> > natural (and fibers don't).
>>>>
>>>> "Everything feels natural"... now thats a scientific argument how
>>>> something "feels"?
>>>>
>>>> I wont go in this benchmark gaggle, but I agree with Marco Roger, the
>>>> level of agression from the sync-haters is ridiculous. And both sides
>>>> eider gaggle around benchmarks, or throw in baseless general
>>>> statements like: "When you create an abstraction layer, it's almost
>>>> always slower.". Thats an argument in 2012? Haven't decades of
>>>> compilers and optimizers tought us (I'm looking at the Assembler vs. C
>>>> arguments back in the 1970s-1980s) that eventually a compiler/optimize
>>>> can work way beyond human abilities to micro-optimize things, and we'd
>>>> rather work on a higher level developing solutions instead of dealing
>>>> with the minuscule things how the electrons are moved around in the
>>>> most efficient way?
>>>>
>>>> So please everybody get a cool head. Syncs are not going to kill you,
>>>> neither is anybody going to be forced to use them, neither is async
>>>> everything that uber cool what you think it is, neither is it not
>>>> going to change the live of everybody.
>>>>
>>>>
>>>>
>>>
>>> --
>>> 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
>>>
>>>
>>> --
>>> 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
>>
>>
> --
> 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

-- 
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

Reply via email to