Created
May 8, 2018 13:42
-
-
Save rivertam/aae3098b16b24f91caabac52c504d4f5 to your computer and use it in GitHub Desktop.
var vs let
This file contains hidden or 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
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