On Aug 9, 2007, at 1:26 PM, [EMAIL PROTECTED] wrote:

> Also, since there are so many Tom's on this mailing list, just call me
> "nym".

It's really a bit of an unusual experience for me.  Family reunions  
excepted, I've never come across as many Toms in one place.  (And I  
really was kidding about picking a name other than "Tom" ;)

> Is this a (much) better test now?

Yes. For starters your now better describing the test as "create and  
observe" rather than just "observe", and are attempting to control  
for creation. This is important, as your claim was based on  
Event.observe. As you can see between your results in test2 and  
test3, a good chunk of the variation was from element creation. (IE  
is much faster on element creation using Prototype's method; Firefox  
is marginally slower.)  But, the test can still use some minor  
improvement.  You're still seeing some slowdown by binding on each  
iteration (which is creating a unique closure each time), rather than  
binding once and caching the result.

i.e., not:

for (i=0; i < 4000; i++) {
   // ...
     Event.observe(el, 'mouseover', changeColor.bindAsEventListener 
(this), false);
   // ...
}

... but rather this, only creating the closure once:

var f = changeColor.bindAsEventListener(this);
for (i=0; i < 4000; i++) {
   // ...
     Event.observe(el, 'mouseover', f, false);
   // ...
}

By binding each time, you're creating another place that might be the  
cause of significant slowdown. Actually, I'm not sure why you're  
binding at all--this test doesn't need to.  If it's just to ensure  
the event gets passed to the callback, Event.observe already handles  
that for you.

e.g.
for (i=0; i < 4000; i++) {
   // ...
     Event.observe(el, 'mouseover', changeColor, false);
   // ...
}

I don't expect enormous speedup from this change, but I do expect  
noticeable speedup (which is not included in numbers, below).

If you take the difference between average "creation" and average  
"create+observe", you get an approximate time of Event.Observe. (This  
may not be entirely accurate, but close enough.) Your test results  
show IE may actually be __faster than Firefox__ w/ Event.observe:  
(using your numbers, as I don't have IE):

Firefox (avg("create+observe") - avg("create") = approx avg("observe")):
3:318 - 0:745 = approx 2:573s.

IE (avg("create+observe") - avg("create")= approx avg("observe")):
2.636 - 0:734 = approx 1:902s.



TAG

P.S. You may also find this link of interest as you seek to optimize  
your current app, which IIRC, is what prompted this test. It includes  
loop optimization suggestion, including reverse loop counting,  
unrolling, and Duff's Device:
http://home.earthlink.net/~kendrasg/info/js_opt/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to