by jcampbell1 · 13y ago · 0 comments
I once went to a meetup presentation where the presenter was a supposed JS performance expert. His presentation was based on JS perf results, and Chrome was consistently showing 749.8M ops per second for complex side-effect free js code.
The only thing I learned from the presentation was that Chrome is good optimizing out code that does nothing, and the presenter's laptop ran at 2.25 Ghz.
However the following examples all do nothing (except increasing i) and get different results.
http://jsperf.com/codethatdoesnothing/2 http://jsperf.com/functionwithwhilethatdoesnothing
JS Perf is fundamentally broken. It doesn't force a side effect, and from the debugger, the first step it does is something like:
while(100,000,000--) {
// your code here
}
The chrome compiler then recognizes the loops can be swapped, and eliminated, thus it runs your code once, yet jsperf thinks it ran it hundreds of millions of times.