I am not surpised . And, I hope jQ team will take notice ? Although improvement might be very difficult to measure since this is inside jQ , and as a such is not likely to happen inside a loop which is 1000000 long. It is more a case of removing unnecessary cleverness, a.k.a. "awesome code" ;o)
Thanks : DBJ PS: I assume you used Safari 4 ? Which is OK. For comprehensive testing usual set of browsers multiplied with usual set of OS-es would be required. But this would be a bit too much considering what is being tested. On May 17, 9:24 pm, Adam <[email protected]> wrote: > After finding the same String constant in the jQuery source I then > found these posts and decided to do some tests using firebug 1.3.3 in > firefox 3.0.10 on a Macbook Pro 2.4GHz. I placed the following code > inside a script tag in an html page > > var n = Number(1000000), str; > function store(a){ > str = a[2];} > > console.time('a'); > while(n--){ > store > ("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split > (","));} > > console.timeEnd('a'); > > Running this returned either 4800->4900 milliseconds or 8800->8900 > milliseconds (I don't know why but every second refresh would produce > the larger value). If I created an Array literal inside the function > call > > var n = Number(1000000), str; > function store(a){ > str = a[2];} > > console.time('a'); > while(n--){ > store > (["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"]);} > > console.timeEnd('a'); > > there was a marked difference and the time returned was always > hovering around 3650->3750 milliseconds. About 25% faster if you don't > count the issue I encountered with every second refresh. > > Admittedly, I am running this loop 100,000 times... > > On Apr 22, 8:50 am, Daniel Friesen <[email protected]> wrote: > > > I'd also like to see the comparison with a chained self callback. > > > (function(o) { > > jQuery.fn[o] = function(f) { > > return this.bind(o, f); > > }; > > return arguments.callee; > > > })("ajaxStart")("ajaxStop")("ajaxComplete")("ajaxError")("ajaxSuccess")("ajaxSend"); > > > ~Daniel Friesen (Dantman, Nadir-Seen-Fire) > > > DBJDBJ wrote: > > > In jQ code one can see string constant splitted into array instead of > > > array constant. For example : > > > > // Attach a bunch of functions for handling common AJAX events > > > jQuery.each > > > ("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split > > > (","), function(i, o) { > > > jQuery.fn[o] = function(f) { > > > return this.bind(o, f); > > > }; > > > }); > > > > This can be seen in several places. I was wondering if using array in > > > this cases would yield faster jQ ? > > > > jQuery.each(["ajaxStart","ajaxStop,ajaxComplete", > > > "ajaxError","ajaxSuccess","ajaxSend"], > > > function(i, o) { > > > jQuery.fn[o] = function(f) { > > > return this.bind(o, f); > > > }; > > > }); > > > > Regards, > > > -- DBJ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" 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/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
