Skip to content

Instantly share code, notes, and snippets.

@willgm
Created November 10, 2016 17:59
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 willgm/cd1eddae37a85195e4d7eb3f061c15f8 to your computer and use it in GitHub Desktop.
Save willgm/cd1eddae37a85195e4d7eb3f061c15f8 to your computer and use it in GitHub Desktop.
[1, 10, 100, 10000, 1000000, 100000000, 1000000000]
.forEach(size => {
console.log('with', size)
console.time('var');
for (var i = 0; i < size; i++) {}
console.timeEnd('var')
console.time('let');
for (let i = 0; i < size; i++) {}
console.timeEnd('let')
});
@willgm
Copy link
Author

willgm commented Nov 10, 2016

Result with node v7.0.0:

$ node var-let-loop.js
with 1
var: 0.082ms
let: 0.014ms
with 10
var: 0.013ms
let: 0.002ms
with 100
var: 0.002ms
let: 0.002ms
with 10000
var: 0.028ms
let: 0.574ms
with 1000000
var: 0.599ms
let: 2.280ms
with 100000000
var: 57.668ms
let: 205.675ms
with 1000000000
var: 557.546ms
let: 2039.702ms

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