Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21330
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: loop through an arry |
| References | <l0tb6o$8a5$1@dont-email.me> <l0tc62$3pr$1@speranza.aioe.org> <GgsYt.30492$VU.28941@fx05.iad> <l0tnar$rnh$1@speranza.aioe.org> |
| Message-ID | <PFIYt.44777$dJ2.1784@fx30.iad> (permalink) |
| Date | 2013-09-13 11:18 -0700 |
On 9/12/13 5:45 PM, Ken wrote:
> On 12.09.2013 18:39, Daniel Pitts wrote:
>> On 9/12/13 2:35 PM, Ken wrote:
>>> need to squeeze out all you can of the browser (which in case you would
>>> use a *while* loop in any case) there is no real problem using your
>>> approach.
>> while and for loops should be identical in performance. They are merely
>> different syntax for the same operations.
>
> Well.. it do depend on browser and implementation (such as JIT) but in
> general while loops are faster as seen here (with most browsers):
>
> http://jsperf.com/fastest-array-loops-in-javascript/32
>
> Disclaimer: I didn't make the test.
>
So many of those tests are flawed. They don't even perform the same
operation!
Anyway, for my browser, the fastest one was a test I created using a for
loop:
for (var l = arr.length; l--;) {
someFn(arr[l]);
}
The second fastest one was a loop that was already there using a while loop:
var l = arr.length;
while(l--) {
someFn(arr[l]);
}
The difference in speed was close to the margin-of-error, so they are
practically equivalent.
Testing in Chrome 29.0.1547.65 on OS X 10.8.4
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
loop through an arry "Tony Johansson" <johansson.andersson@telia.com> - 2013-09-12 23:19 +0200
Re: loop through an arry Adrián Espinosa <mortuuslordofdeads@gmail.com> - 2013-09-12 14:30 -0700
Re: loop through an arry Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-13 03:17 +0200
Re: loop through an arry Stefan Weiss <krewecherl@gmail.com> - 2013-09-13 04:27 +0200
Re: loop through an arry Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-13 05:23 +0200
Re: loop through an arry Stefan Weiss <krewecherl@gmail.com> - 2013-09-13 05:36 +0200
Re: loop through an arry "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-09-13 09:48 +0200
Re: loop through an arry Ken <usenet-so@abdiassoftware.com> - 2013-09-12 16:35 -0500
Re: loop through an arry Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-12 16:39 -0700
Re: loop through an arry Ken <usenet-so@abdiassoftware.com> - 2013-09-12 19:45 -0500
Re: loop through an arry Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-13 11:18 -0700
Re: loop through an arry Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-14 01:49 +0200
Re: loop through an arry Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-09-13 17:06 -0700
csiph-web