Skip to content

Instantly share code, notes, and snippets.

@cmcculloh
Created January 14, 2011 17:46
Show Gist options
  • Save cmcculloh/779945 to your computer and use it in GitHub Desktop.
Save cmcculloh/779945 to your computer and use it in GitHub Desktop.
Speed testing local vs namespaced vs global var
var n = 0,
i = 0,
GL = {
i: 0,
};
//incrementation on a local variable
console.time('local');
n = 0;
while(n < 2000000){
var j = 0;
j++;
n++;
}
console.timeEnd('local');
//incrementation on a namespaced variable
console.time('Namespaced');
n = 0;
while(n < 2000000){
GL.i++;
n++;
}
console.timeEnd('Namespaced');
//incrementation on a global variable
console.time('global');
n = 0;
while(n < 2000000){
i++;
n++;
}
console.timeEnd('global');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment