Register vs Memory

JavaScript performance comparison

Test case created by Joshua Piccari

Info

This test demonstrates a V8 optimization in which variables used in loops are stored in CPU registers instead of memory. V8 will opt-out of this optimization if the variable used in the loop is used in a closure.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Register
var i, sum, sum2;

for(i = 0, sum = 0; i < 100000; i++) { sum += Math.sqrt(i); }

sum2 = sum;
setTimeout(function() { i = sum2; }, 0);
pending…
Memory
var i, sum, sum2;

for(i = 0, sum = 0; i < 100000; i++) { sum += Math.sqrt(i); }

sum2 = sum;
setTimeout(function() { i = sum; }, 0);
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