comparison of repeated lookups vs storing in variable

Benchmark created by Archy The Brave on


Setup

var array = [0,1,2,3,4,5,6,7,8,9];
    var func = function(e){return e*e;};

Test runner

Ready to run.

Testing in
TestOps/sec
3x Declare Var
var u = array[3];
for (var j=0;j<3;j++) {
    func(u);  
}
ready
3x Repeat
for (var j=0;j<3;j++) {
    func(array[3]);  
}
ready
10x Declare Var
var u = array[3];
for (var j=0;j<10;j++) {
    func(u);  
}
ready
10x Repeat
for (var j=0;j<10;j++) {
    func(array[3]);  
}
ready
100x Declare Var
var u = array[3];
for (var j=0;j<100;j++) {
    func(u);  
}
ready
100x Repeat
for (var j=0;j<100;j++) {
    func(array[3]);  
}
ready
1000x Declare Var
var u = array[3];
for (var j=0;j<1000;j++) {
    func(u);  
}
ready
1000x Repeat
for (var j=0;j<1000;j++) {
    func(array[3]);  
}
ready

Revisions

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

  • Revision 1: published by Archy The Brave on