Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance difference between +=, ++, +

Tags:

javascript

I created this test http://jsperf.com/loop-counter why is there such a difference between these three expressions.

like image 331
Alistair Laing Avatar asked Mar 25 '11 14:03

Alistair Laing


People also ask

What is the meaning by performance?

the act of performing a ceremony, play, piece of music, etc. the execution or accomplishment of work, acts, feats, etc. a particular action, deed, or proceeding. an action or proceeding of an unusual or spectacular kind: His temper tantrum was quite a performance. the act of performing.

What a good performance meaning?

Someone's or something's performance is how successful they are or how well they do something.

How do you describe outstanding performance?

The employee exceeds established expectations as measured by results, consistent work quality, quantity and timeliness in most areas of responsibility. He or she exhibits mastery in most dimensions of the work performed, making a significant contribution in support of the department, division or university goals.

Is performance countable or uncountable?

(countable) A performance is a show of acting or music. We went to see a performance by local musicians last night. The acting was good, but the noise made it difficult to enjoy the performance.


3 Answers

because your test is wrong. you're reusing the same variable, so the larger it gets, the slower it is to increment. take a look at this: http://jsperf.com/loop-counter/6

this is how jsperf works - preparation code is run only once, before all tests.

like image 75
wildcard Avatar answered Oct 05 '22 18:10

wildcard


I tried running all three tests several times, and each time I reload the page, the first test I try is the fastest by far.

So I'm guessing there is some issue with the test being too short, i.e. the code that runs the tests is taking up most of the time.

like image 34
kolufild Avatar answered Oct 05 '22 19:10

kolufild


If this is not a rhetorical question and you actually want an aswer then: becuse of how people have written the JS engine in the browsers.

like image 44
vbence Avatar answered Oct 05 '22 19:10

vbence