Skip to content

Instantly share code, notes, and snippets.

@rivertam
Created May 8, 2018 13:42
Show Gist options
  • Save rivertam/aae3098b16b24f91caabac52c504d4f5 to your computer and use it in GitHub Desktop.
Save rivertam/aae3098b16b24f91caabac52c504d4f5 to your computer and use it in GitHub Desktop.
var vs let
const benchmark = require('benchmark');
const suite = new benchmark.Suite();
suite.add('var loop', () => {
var hi, i, list;
list = [];
for (i = 0; i < 50; ++i) {
hi = { str: 'hi', i };
list.push(hi);
}
})
.add('let loop', () => {
const list = [];
for (let i = 0; i < 50; ++i) {
const hi = { str: 'hi', i };
list.push(hi);
}
})
.on('cycle', event => {
console.log(String(event.target));
})
.on('complete', function () {
console.log('fastest is', this.filter('fastest').map('name'));
})
.run({ async: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment