From: Thomas 'PointedEars' Lahn on 15 Jan 2010 08:09 Jorge wrote: > Thomas 'PointedEars' Lahn wrote: >> Jorge wrote: >> > var i= 1e6, a= [], d= +new Date(); >> > while (i--) { a[i]= ""; } >> > console.log(+new Date()- d); >> >> Idiot. That's a *while* loop that *sets array elements*. Not a *for* >> loop that *does not*. > > (load applause) You are such a complete idiot. > *You* posted this code: > > for (var i = len; i--;) { > var o = library[i]; > photos[i] = o.img; > captions[i] = o.caption; > } > > And *you* said: "Benchmarks suggest it would be about 20% faster in > TraceMonkey 1.9.1.6.". In <news:2756852.MLUfLXkozy(a)PointedEars.de>. Which is exactly what I measured. (Faster than *what*, stupid? Now what have I been referring to there?). Neither of which disproves the statement about `for' loops I made in the precursor, <news:1306342.kT8p0MMh6R(a)PointedEars.de>, that you tried to disprove with your flawed test case, <news:a34ddd71-fee2-488e b3f0-45812027f7bd(a)r24g2000yqd.googlegroups.com>. Get a brain, Jorge. PointedEars -- Danny Goodman's books are out of date and teach practices that are positively harmful for cross-browser scripting. -- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)
From: Jorge on 15 Jan 2010 08:57 On Jan 15, 2:09 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > (... whining ...) Pointy, whine as much as you like, but your "optimized" code does in fact run *slower*. -- Jorge.
From: Jorge on 15 Jan 2010 09:03 On Jan 15, 1:47 pm, Jorge <jo...(a)jorgechamorro.com> wrote: > > (load applause) s/load/loud/ -- Jorge.
From: Thomas 'PointedEars' Lahn on 15 Jan 2010 11:16 Garrett Smith wrote: > var imgArray = library.map(filterByName("img")); > var captionArray = library.map(filterByName("caption")); > [...] > > Where not supported, Array.prototype.map functionality can be added, as > indicated on MDC page[1]. What a waste. If an Array prototype method should be used here, then Array.prototype.forEach(). > Writing your own loop would be fastest here. No argument there. PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann
From: Garrett Smith on 15 Jan 2010 13:07
Thomas 'PointedEars' Lahn wrote: > Garrett Smith wrote: > >> var imgArray = library.map(filterByName("img")); >> var captionArray = library.map(filterByName("caption")); >> [...] >> >> Where not supported, Array.prototype.map functionality can be added, as >> indicated on MDC page[1]. > > What a waste. If an Array prototype method should be used here, then > Array.prototype.forEach(). > Array.prototype.forEach calls a supplied function on each element in the Array. It does not create a new Array. Array.prototype.map creates a new array with the results of calling a supplied function on each element in the array. And yes, much more efficient to just loop it yourself. -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/ |