Skip to content

Instantly share code, notes, and snippets.

@ericdum
Last active August 29, 2015 13:58
Show Gist options
  • Save ericdum/10118355 to your computer and use it in GitHub Desktop.
Save ericdum/10118355 to your computer and use it in GitHub Desktop.
test-for.js
var timers = {};
if ( console && !console.time ) {
console.time = function( name ) {
if ( name ) {
timers[ name ] = Date.now();
}
}
console.timeEnd = function( name ) {
if ( timers[ name ] ) {
console.log( name + ': ' + (Date.now() - timers[ name ]) + 'ms' );
delete timers[ name ];
}
}
}
function test1(){console.time('test a');
b = {a:{b:{c:{d:{e:{f:{g:{length:1000000}}}}}}}}
for(var i=0; i<b.a.b.c.d.e.f.g.length; i++) ;
console.timeEnd('test a');
}
function test2(){console.time('test b');
b = {a:{b:{c:{d:{e:{f:{g:{length:1000000}}}}}}}}
c = b.a.b.c.d.e.f.g.length
for(var i=0; i<c; i++) ;
console.timeEnd('test b');
}
for(var i=0; i<10; i++)test1()
for(var i=0; i<10; i++)test2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment