Hi,

after having read some comments about loop optimization somewhere, I ran
some very simple minded tests with JS for loops just loading the code
directly from the file system and found on a Lenovo X60 with Ubuntu Jaunty:

var d = [];
d[50000000]=50000000;

for (i=0; i<d.length); i++) {}                  // A
len = d.length; for (i=0; i<d.length); i++) {}  // B


- B is more than 15% faster with FF3.5.3 and about 20% faster with Chrome
   4.0.213.0 (Ubuntu build 26919)

- Firefox 3.5.3 is about 3.5 times faster than Chrome

- while and do/while loops are significantly faster than for loops in
   Chrome, but slower in FF.

As the current SVN trunk of Qooxdoo has 877 type A loop statements in
framework/source/class/qx/ I thought it might be worthwhile to change these
loops from

    for (i=0; i<d.length); i++) {}

to

    for (i=0, len=d.length; i<len); i++) {}

where the array length doesn't change within the for loop.

Thinking a bit further I figured that the performance gain might be marginal
for any significant amount of code inside the loop. And indeed, adding just
the simple line

        r = n*33;

inside the loop made the difference in the for loops disappear, even for n=0
...

So, I guess, measuring when trying to optimize for performance makes a lot
of sense ... and just optimizing the control structure of a look doesn't
gain that much. So the code inside the loop is where to search for
improvements.

Not really a very deep insight, but I thought I want to share this with you
anyway, as these kinds of "urban coding myth" come up every once in a while.

Cheers,
Fritz

-- 
Oetiker+Partner AG              tel: +41 62 775 99 03 (direct)
Fritz Zaucker                        +41 62 775 99 00 (switch board)
Aarweg 15                            +41 79 675 06 30 (mobile)
CH-4600 Olten                   fax: +41 62 775 99 05
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
qooxdoo-devel mailing list
qooxdoo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to