Re: Best method to increment a variable.
- From: DS <ds@xxxxxxxxxxx>
- Date: Sun, 16 Dec 2007 14:12:54 -0000
On Sun, 16 Dec 2007 02:46:22 -0800, Steve wrote:
Several textbooks, including Javascript for Dummies (2005), show the
"i=++i" method of incrementing a variable. I have been using this method
but I have been recently informed by some experts in the Google Maps API
group that this method is confusing and wasteful of resources and is now
redundant and I should use "++i" or "i=i+1". Any strong opinions in this
group?
Profile your code first! There is absolutely zero point in optimizing
something which may have 1% or less performance degradation on your code.
Instead, work at optimizing your code which consumes most of the CPU. Use
firebug's profiler to determine the functions your code is spending most
of its time.
Without taking any direct measurements, I would assume i++ and ++i will
be the most efficient when using most javascript engines because the
other expressions will probably introduce temporary variables.
.
- Follow-Ups:
- Re: Best method to increment a variable.
- From: Dr J R Stockton
- Re: Best method to increment a variable.
- References:
- Best method to increment a variable.
- From: Steve
- Best method to increment a variable.
- Prev by Date: Re: typeof for feature testing host methods
- Next by Date: anti-MI5 filter
- Previous by thread: Re: Best method to increment a variable.
- Next by thread: Re: Best method to increment a variable.
- Index(es):
Relevant Pages
|