Skip to content

Instantly share code, notes, and snippets.

@cswl
Created July 16, 2016 13:46
Show Gist options
  • Save cswl/741078318d2e608732f6a9b51e6b497c to your computer and use it in GitHub Desktop.
Save cswl/741078318d2e608732f6a9b51e6b497c to your computer and use it in GitHub Desktop.
var microtime = require('microtime')
// @microtimer
// function for_let_loop() .. okay no :(
{ //block scoping :D
const start = microtime.now();
for(let i = 0; i < 1e8; ++i){}
const end = microtime.now();
console.log(`for_let_loop took ${end-start}us`);
}
{ //block scoping :D
const start = microtime.now();
let i = 0;
for(; i < 1e8; ++i){}
const end = microtime.now();
console.log(`for_let_outside took ${end-start}us`);
}
{ //block scoping :D
const start = microtime.now();
let i = 0;
for(; i < 1e8; ++i){const k=i;}
const end = microtime.now();
console.log(`for_let_outside_const_inside took ${end-start}us`);
}
{ //block scoping :D
const start = microtime.now();
let i = 0;
for(; i < 1e8; ++i){let k=i;}
const end = microtime.now();
console.log(`for_let_outside_let_inside took ${end-start}us`);
}
// var isn't block scoped anyway :|
const start = microtime.now();
for(var i = 0; i < 1e8; ++i){}
const end = microtime.now();
console.log(`for_var_loop took ${end-start}us`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment