Check this test case:
n = n + 1;
is faster than
n++;
and
++n;
Any clue about why the first writing is so much faster on many browsers ?
Check this test case: http://jsperf./n-n-1-or-n
n = n + 1;
is faster than
n++;
and
++n;
Any clue about why the first writing is so much faster on many browsers ?
--
and ++
.
– Oded
Commented
Jan 12, 2013 at 8:49
The performance will differ by browser and puter.
I see that n = n + 1
on my setup is about 4 times faster.
At the same time, the slowest is over 62 million ops per second.
You are micro-optimizing here. The usage of one over another is hardly going to be a bottleneck.
Why it is faster in some browsers? I don't know. You would need to dig into the source code of the different JavaScript engines to find out.
Chances are good that there is an optimization for this case due to how some popular micro-benchmarks are written.
Check this test. Or here is another test.