closure effect

JavaScript performance comparison

Test case created

Info

Testing the impact of closure on variable promotion.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var globalVar = 0;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
closure problem
var sum = 0;
for ( var i = 0; i < 1000; ++i ) {
   sum += Math.sqrt( i );
}

var sum1 = sum;
setTimeout( function() { globalVar += sum1; }, 1 );
pending…
Problem fixed
var sum = 0;
for ( var i = 0; i < 1000; ++i ) {
   sum += Math.sqrt( i );
}

var sum2 = sum;

setTimeout( function() { globalVar += sum2; }, 1 );
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment