Skip to content

Instantly share code, notes, and snippets.

@alippai
Created March 1, 2014 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alippai/f257726dd8c621713fee to your computer and use it in GitHub Desktop.
Save alippai/f257726dd8c621713fee to your computer and use it in GitHub Desktop.
Bug?
var b;
var o = {b : 1};
var count1 = 0, count2 = 0, count3 = 0;
console.time('global');
while (b = 1) {
if (count1 > 1000*1000) break;
count1 += b;
}
console.timeEnd('global');
console.time('global object');
while (true) {
if (count2 > 1000*1000) break;
count2 += o.b;
}
console.timeEnd('global object');
console.time('local');
while (true) {
var c = 1;
if (count3 > 1000*1000) break;
count3 += c;
}
console.timeEnd('local');
console.log(count1, count2, count3);
@alippai
Copy link
Author

alippai commented Mar 1, 2014

IE 11:
global: 3.6150ms
global object: 3.4786ms
local: 3.4637ms

Chrome Canary:
global: 14.435ms
global object: 3.006ms
local: 218.870ms

FF:
global: 3.22ms
global object: 2.87ms
local: 2.78ms

FF (nighly):
global: 3.33ms
global object: 2.82ms
local: 2.79ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment