Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #10657
| From | Dr J R Stockton <reply1204@merlyn.demon.co.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Initialize multi-dimensional array |
| Date | 2012-01-27 20:09 +0000 |
| Organization | Home |
| Message-ID | <giyHRmBRSwIPFwB3@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | <81f35d2e-80d0-45aa-965a-c0093cbf4fbf@b23g2000yqn.googlegroups.com> <tWjEMKGVkFIPFwTj@invalid.uk.co.demon.merlyn.invalid> <3g81i7l6qma04ij6jsef0hjprjochsvq4q@4ax.com> |
In comp.lang.javascript message <3g81i7l6qma04ij6jsef0hjprjochsvq4q@4ax.
com>, Thu, 26 Jan 2012 11:56:11, Ross McKay <au.org.zeta.at.rosko@invali
d.invalid> posted:
>On Wed, 25 Jan 2012 19:33:41 +0000, Dr J R Stockton wrote:
>
>>[...] A while loop counting down
>>is probably shorter & faster than a for loop counting up, [...]
>
>No.
>
>http://jsperf.com/caching-array-length/4
I prefer to rely on my own tests, done with a large enough loop for time
to begin to matter.
var A, J, K_ = 777 // increase v put code in those
D0_ = new Date()
Q_ = K_ ;
D1_ = new Date()
Q_ = K_ ; while (Q_--) { }
D2_ = new Date()
Q_ = K_ ; while (Q_--) { A = [] ; J = K_ ; while (--J) A[J] = J }
D3_ = new Date()
Q_ = K_ ; while (Q_--) { A = [] ; for (J = 0 ; J < K_ ; J++) A[J] = J }
D4_ = new Date()
Q_ = [D1_-D0_, D2_-D1_, D3_-D2_, D4_-D3_] // times // Demo 6
The while loop is clearly shorter. And I find it faster in three
browsers out of five.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Initialize multi-dimensional array Archos <raul.san@sent.com> - 2012-01-24 15:09 -0800
Re: Initialize multi-dimensional array Denis McMahon <denismfmcmahon@gmail.com> - 2012-01-25 09:56 +0000
Re: Initialize multi-dimensional array Andreas Bergmaier <andber93@web.de> - 2012-01-25 11:48 +0100
Re: Initialize multi-dimensional array Archos <raul.san@sent.com> - 2012-01-25 04:37 -0800
Re: Initialize multi-dimensional array Richard Cornford <Richard@litotes.demon.co.uk> - 2012-01-25 06:35 -0800
Re: Initialize multi-dimensional array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-25 19:39 +0100
Re: Initialize multi-dimensional array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-28 01:42 +0100
Re: Initialize multi-dimensional array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-25 09:38 -0800
Re: Initialize multi-dimensional array Dr J R Stockton <reply1204@merlyn.demon.co.uk> - 2012-01-25 19:33 +0000
Re: Initialize multi-dimensional array Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2012-01-26 11:56 +1100
Re: Initialize multi-dimensional array Dr J R Stockton <reply1204@merlyn.demon.co.uk> - 2012-01-27 20:09 +0000
csiph-web