Last active
August 29, 2015 13:58
-
-
Save ericdum/10118355 to your computer and use it in GitHub Desktop.
test-for.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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