Re: [Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-30 Thread Richard Quadling
2009/12/17 T.J. Crowder t...@crowdersoftware.com:
 Forget the CPU cycles, it's the brain cycles I want back.

 But it was all worth it to learn about JSLitmus. :-)

 On Dec 17, 3:33 pm, Bob Kerns r...@acm.org wrote:
 Not to be a curmudgeon about it -- I'll just point out that the CPU cycles
 consumed in processing the email for this discussion far exceeds the CPU
 cycles saved by all the code the lot of you will ever write with such
 tweaks.

 Purely entertainment / mental game play.

 If you want to improve performance, the mental effort would be better spent
 looking at your algorithm, or even better, measuring the performance to find
 where you need to focus your attention. I can tell you now it won't be your
 choice of iteration statements!

 Play on -- I just wanted to put it into context...

 --
 You received this message because you are subscribed to the Google Groups 
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to 
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at 
 http://groups.google.com/group/prototype-core?hl=en

Well I'm glad you all had a little look. These sorts of things don't
often mean much.

OOI.

++i, ++i vs i += 2 also seems to be a little better.

-- 
-
Richard Quadling
Standing on the shoulders of some very clever giants!
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


[Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-17 Thread T.J. Crowder
Thanks for that info and link, Robert! Obviously, we who develop web
apps for normal users should leave the setting alone most of the time,
but good to know we can change it for these sorts of tests. (And wow,
I thought it was a time limit; that explains why something I was doing
the other day was giving me this error way faster than I expected.)

Results for IE7 on Windows XP:

http://tinyurl.com/y8fb77y
http://tinyurl.com/yd3vuzz
http://tinyurl.com/ydqgvwr
http://tinyurl.com/ye8hwvb

(I find it's best to run these tests multiple times.) Basically, it's
a wash (++i or i++), but i += 1 is markedly slower. As you say,
Robert, unlikely to make any difference in the real world.

I'd post Chrome and Firefox results for Windows, but I kept getting
infinite numbers of operations per second! ;-) Chrome (of course!) did
an infinite number of ops/second on all of the tests. Firefox
alternated between infinite numbers of ++i and i++ operations -- so
probably a wash there too.

Now, since I apparently have the power to do infinite numbers of
calculations, I'm off to break some RSA keys...

-- T.J. ;-)

On Dec 16, 2:48 pm, Robert Kieffer bro...@gmail.com wrote:
 Unfortunately IE limits scripts to 5M statements, rather than limiting by
 time.  That limit was set back in the days of IE4, when 5M statements would
 take ~10 seconds to run.  But newer hardware/script engines hit that in a
 fraction of a second now... which is why you're seeing it.

 The workaround is to edit your registry to increase the limit to 50M
 statements (or more). This MS article explains how, and provides a bit more
 background on  of this ( ridiculous) behavior.

 http://support.microsoft.com/default.aspx?scid=kb;en-us;175500



 On Wed, Dec 16, 2009 at 4:44 AM, Allen Madsen bla...@gmail.com wrote:
  I tried running your test on IE8 and it just kept prompting me with script
  unresponsive.

  Allen Madsen
 http://www.allenmadsen.com

  On Wed, Dec 16, 2009 at 7:01 AM, Robert Kieffer bro...@gmail.com wrote:

  I whipped up a quick JSLitmus test to try out a handful of empty loops
  (using i++, ++i, i+=1, and a while loop:
 http://www.broofa.com/Tools/JSLitmus/tests/loop_operators.html

  View the [very short] source of the page to see the actual test code.
  When running the test for yourself, be sure to uncheck the normalize box.
  Also, you'll probably want to run each test a few times to make sure you're
  getting consistent results (CPU load elsewhere in the OS can skew resutls).
  For more on JSLitmus, readhttp://www.broofa.com/Tools/JSLitmus)

  Here are the results I got on my MacBook (sorry, don't have IE results
  handy)
  FF:http://tinyurl.com/ykdutyk
  Safari:http://tinyurl.com/yzusg7e
  Opera:http://tinyurl.com/yjamzwc
  Chrome:http://tinyurl.com/ylylyw5

  Executive summary: On the above browsers, performance does vary. i++ or
  ++i are the best all-round performers, while the while() loop is generally
  not as good.  However on all of these systems ('cept Opera), looping code
  runs so fast that performance is negligable compared to whatever code you
  put inside the loop.  I.e. it's unlikely to matter in all but the most
  trivial of loops.

  - rwk

  On Wed, Dec 16, 2009 at 2:28 AM, Yaffle vic99...@yandex.ru wrote:

  ++i; is a little more efficient in C language,
  in javascript difference in performance of all these operators is tiny

  On Dec 16, 3:21 pm, RQuadling rquadl...@googlemail.com wrote:
   Hi.

   Is there any consensus on which is more efficient in a for() loop?

   I was taught that for ++i being the most efficient.

   I've created 2 patches (++ and a +1) in case anyone is interested.

  http://pastie.org/private/3rgonpsn90yjd17q9zwa
   andhttp://pastie.org/private/qufy3rwmaevxc1sysvq

   From what I've read, this could be a little pointless, but I'm not the
   expert in this area.

   Regards,

   Richard.

  --
  You received this message because you are subscribed to the Google Groups
  Prototype: Core group.
  To post to this group, send email to prototype-core@googlegroups.com
  To unsubscribe from this group, send email to
  prototype-core-unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en

   --
  You received this message because you are subscribed to the Google Groups
  Prototype: Core group.
  To post to this group, send email to prototype-core@googlegroups.com
  To unsubscribe from this group, send email to
  prototype-core-unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en

   --
  You received this message because you are subscribed to the Google Groups
  Prototype: Core group.
  To post to this group, send email to prototype-core@googlegroups.com
  To unsubscribe from this group, send email to
  prototype-core-unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en

-- 
You received this message 

Re: [Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-17 Thread Robert Kieffer
T.J.

Be sure you've unchecked the normalize results checkbox.  That will get
rid of the infinite ops/sec.

FWIW, that checkbox is provided as a way of subtracting out the time
required to do an empty loop when computing test performance.  In 99% of
cases, where you're interested in testing the performance of what's inside
the iteration loop and not the loop code itself, you want that box checked.

In this particular case, though, we're testing empty loop performance, so it
needs to be unchecked.  (And, of course, subtracting out that time usually
yields a zero result - hence the infinite ops/second.  So, yeah, as long as
you can break RSA keys using empty code blocks, knock yourself out!)

- rwk ;-)

On Thu, Dec 17, 2009 at 12:53 AM, T.J. Crowder t...@crowdersoftware.comwrote:


 I'd post Chrome and Firefox results for Windows, but I kept getting
 infinite numbers of operations per second! ;-) Chrome (of course!) did
 an infinite number of ops/second on all of the tests. Firefox
 alternated between infinite numbers of ++i and i++ operations -- so
 probably a wash there too.

 Now, since I apparently have the power to do infinite numbers of
 calculations, I'm off to break some RSA keys...

 -- T.J. ;-)



-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en

[Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-17 Thread Diego Perini

Here is a small quoted text from Andrea Giammarchi on tweetter:

[quote]
i++ returns a new Number with i value then increments the i
reference, while ++i execute just the second step -
that is why I prefer ++i
[/quote]

this should be the same with both pre-increment and pre-decrement
and in my tests while loops are generally faster than for loops.


Diego


On Dec 17, 11:58 am, Robert Kieffer bro...@gmail.com wrote:
 T.J.

 Be sure you've unchecked the normalize results checkbox.  That will get
 rid of the infinite ops/sec.

 FWIW, that checkbox is provided as a way of subtracting out the time
 required to do an empty loop when computing test performance.  In 99% of
 cases, where you're interested in testing the performance of what's inside
 the iteration loop and not the loop code itself, you want that box checked.

 In this particular case, though, we're testing empty loop performance, so it
 needs to be unchecked.  (And, of course, subtracting out that time usually
 yields a zero result - hence the infinite ops/second.  So, yeah, as long as
 you can break RSA keys using empty code blocks, knock yourself out!)

 - rwk ;-)

 On Thu, Dec 17, 2009 at 12:53 AM, T.J. Crowder 
 t...@crowdersoftware.comwrote:



  I'd post Chrome and Firefox results for Windows, but I kept getting
  infinite numbers of operations per second! ;-) Chrome (of course!) did
  an infinite number of ops/second on all of the tests. Firefox
  alternated between infinite numbers of ++i and i++ operations -- so
  probably a wash there too.

  Now, since I apparently have the power to do infinite numbers of
  calculations, I'm off to break some RSA keys...

  -- T.J. ;-)

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


Re: [Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-17 Thread Bob Kerns
Not to be a curmudgeon about it -- I'll just point out that the CPU cycles
consumed in processing the email for this discussion far exceeds the CPU
cycles saved by all the code the lot of you will ever write with such
tweaks.

Purely entertainment / mental game play.

If you want to improve performance, the mental effort would be better spent
looking at your algorithm, or even better, measuring the performance to find
where you need to focus your attention. I can tell you now it won't be your
choice of iteration statements!

Play on -- I just wanted to put it into context...

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en

Re: [Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-17 Thread Ryan Gahl
+1,000,000,000 (cycles)

-1 on downplaying really nerdy optimizations :)

you curmudgeon you (nice word, btw)

---
Warm Regards,
Ryan Gahl


On Thu, Dec 17, 2009 at 9:33 AM, Bob Kerns r...@acm.org wrote:

 Not to be a curmudgeon about it -- I'll just point out that the CPU cycles
 consumed in processing the email for this discussion far exceeds the CPU
 cycles saved by all the code the lot of you will ever write with such
 tweaks.

 Purely entertainment / mental game play.

 If you want to improve performance, the mental effort would be better spent
 looking at your algorithm, or even better, measuring the performance to find
 where you need to focus your attention. I can tell you now it won't be your
 choice of iteration statements!

 Play on -- I just wanted to put it into context...

 --
 You received this message because you are subscribed to the Google Groups
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en


-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en

[Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-17 Thread T.J. Crowder
Forget the CPU cycles, it's the brain cycles I want back.

But it was all worth it to learn about JSLitmus. :-)

On Dec 17, 3:33 pm, Bob Kerns r...@acm.org wrote:
 Not to be a curmudgeon about it -- I'll just point out that the CPU cycles
 consumed in processing the email for this discussion far exceeds the CPU
 cycles saved by all the code the lot of you will ever write with such
 tweaks.

 Purely entertainment / mental game play.

 If you want to improve performance, the mental effort would be better spent
 looking at your algorithm, or even better, measuring the performance to find
 where you need to focus your attention. I can tell you now it won't be your
 choice of iteration statements!

 Play on -- I just wanted to put it into context...

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


[Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-16 Thread Yaffle
++i; is a little more efficient in C language,
in javascript difference in performance of all these operators is tiny


On Dec 16, 3:21 pm, RQuadling rquadl...@googlemail.com wrote:
 Hi.

 Is there any consensus on which is more efficient in a for() loop?

 I was taught that for ++i being the most efficient.

 I've created 2 patches (++ and a +1) in case anyone is interested.

 http://pastie.org/private/3rgonpsn90yjd17q9zwa
 andhttp://pastie.org/private/qufy3rwmaevxc1sysvq

 From what I've read, this could be a little pointless, but I'm not the
 expert in this area.

 Regards,

 Richard.

-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en


Re: [Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-16 Thread Allen Madsen
I tried running your test on IE8 and it just kept prompting me with script
unresponsive.

Allen Madsen
http://www.allenmadsen.com


On Wed, Dec 16, 2009 at 7:01 AM, Robert Kieffer bro...@gmail.com wrote:

 I whipped up a quick JSLitmus test to try out a handful of empty loops
 (using i++, ++i, i+=1, and a while loop:
 http://www.broofa.com/Tools/JSLitmus/tests/loop_operators.html

 View the [very short] source of the page to see the actual test code.  When
 running the test for yourself, be sure to uncheck the normalize box. Also,
 you'll probably want to run each test a few times to make sure you're
 getting consistent results (CPU load elsewhere in the OS can skew resutls).
 For more on JSLitmus, read http://www.broofa.com/Tools/JSLitmus )

 Here are the results I got on my MacBook (sorry, don't have IE results
 handy)
 FF: http://tinyurl.com/ykdutyk
 Safari: http://tinyurl.com/yzusg7e
 Opera: http://tinyurl.com/yjamzwc
 Chrome: http://tinyurl.com/ylylyw5

 Executive summary: On the above browsers, performance does vary. i++ or ++i
 are the best all-round performers, while the while() loop is generally not
 as good.  However on all of these systems ('cept Opera), looping code runs
 so fast that performance is negligable compared to whatever code you put
 inside the loop.  I.e. it's unlikely to matter in all but the most trivial
 of loops.

 - rwk



 On Wed, Dec 16, 2009 at 2:28 AM, Yaffle vic99...@yandex.ru wrote:

 ++i; is a little more efficient in C language,
 in javascript difference in performance of all these operators is tiny


 On Dec 16, 3:21 pm, RQuadling rquadl...@googlemail.com wrote:
  Hi.
 
  Is there any consensus on which is more efficient in a for() loop?
 
  I was taught that for ++i being the most efficient.
 
  I've created 2 patches (++ and a +1) in case anyone is interested.
 
  http://pastie.org/private/3rgonpsn90yjd17q9zwa
  andhttp://pastie.org/private/qufy3rwmaevxc1sysvq
 
  From what I've read, this could be a little pointless, but I'm not the
  expert in this area.
 
  Regards,
 
  Richard.

 --
 You received this message because you are subscribed to the Google Groups
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en


  --
 You received this message because you are subscribed to the Google Groups
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en


-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en

Re: [Prototype-core] Re: For() loops, ++i, i++, i+=1

2009-12-16 Thread Robert Kieffer
Unfortunately IE limits scripts to 5M statements, rather than limiting by
time.  That limit was set back in the days of IE4, when 5M statements would
take ~10 seconds to run.  But newer hardware/script engines hit that in a
fraction of a second now... which is why you're seeing it.

The workaround is to edit your registry to increase the limit to 50M
statements (or more). This MS article explains how, and provides a bit more
background on  of this ( ridiculous) behavior.

http://support.microsoft.com/default.aspx?scid=kb;en-us;175500

On Wed, Dec 16, 2009 at 4:44 AM, Allen Madsen bla...@gmail.com wrote:

 I tried running your test on IE8 and it just kept prompting me with script
 unresponsive.

 Allen Madsen
 http://www.allenmadsen.com


 On Wed, Dec 16, 2009 at 7:01 AM, Robert Kieffer bro...@gmail.com wrote:

 I whipped up a quick JSLitmus test to try out a handful of empty loops
 (using i++, ++i, i+=1, and a while loop:
 http://www.broofa.com/Tools/JSLitmus/tests/loop_operators.html

 View the [very short] source of the page to see the actual test code.
 When running the test for yourself, be sure to uncheck the normalize box.
 Also, you'll probably want to run each test a few times to make sure you're
 getting consistent results (CPU load elsewhere in the OS can skew resutls).
 For more on JSLitmus, read http://www.broofa.com/Tools/JSLitmus )

 Here are the results I got on my MacBook (sorry, don't have IE results
 handy)
 FF: http://tinyurl.com/ykdutyk
 Safari: http://tinyurl.com/yzusg7e
 Opera: http://tinyurl.com/yjamzwc
 Chrome: http://tinyurl.com/ylylyw5

 Executive summary: On the above browsers, performance does vary. i++ or
 ++i are the best all-round performers, while the while() loop is generally
 not as good.  However on all of these systems ('cept Opera), looping code
 runs so fast that performance is negligable compared to whatever code you
 put inside the loop.  I.e. it's unlikely to matter in all but the most
 trivial of loops.

 - rwk



 On Wed, Dec 16, 2009 at 2:28 AM, Yaffle vic99...@yandex.ru wrote:

 ++i; is a little more efficient in C language,
 in javascript difference in performance of all these operators is tiny


 On Dec 16, 3:21 pm, RQuadling rquadl...@googlemail.com wrote:
  Hi.
 
  Is there any consensus on which is more efficient in a for() loop?
 
  I was taught that for ++i being the most efficient.
 
  I've created 2 patches (++ and a +1) in case anyone is interested.
 
  http://pastie.org/private/3rgonpsn90yjd17q9zwa
  andhttp://pastie.org/private/qufy3rwmaevxc1sysvq
 
  From what I've read, this could be a little pointless, but I'm not the
  expert in this area.
 
  Regards,
 
  Richard.

 --
 You received this message because you are subscribed to the Google Groups
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en


  --
 You received this message because you are subscribed to the Google Groups
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en


  --
 You received this message because you are subscribed to the Google Groups
 Prototype: Core group.
 To post to this group, send email to prototype-core@googlegroups.com
 To unsubscribe from this group, send email to
 prototype-core-unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/prototype-core?hl=en


-- 
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en