Skip to content

Instantly share code, notes, and snippets.

@ericdum
Last active August 29, 2015 13:58
Show Gist options
  • Save ericdum/10120924 to your computer and use it in GitHub Desktop.
Save ericdum/10120924 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<body>
<script>
var timers = {};
var _console = {};
var _console_cache = [];
_console.time = function( name ) {
if ( name ) {
timers[ name ] = (new Date());
}
}
_console.timeEnd = function( name ) {
if ( timers[ name ] ) {
_console_cache.push( name + ': ' + ((new Date()) - timers[ name ]) + 'ms' );
delete timers[ name ];
}
}
function test1(){_console.time('test a');
b = {a:{b:{c:{d:{e:{f:{g:{length:100000000}}}}}}}}
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:100000000}}}}}}}}
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()
for(var i in _console_cache)document.write(_console_cache[i]+"</br>")
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment