Last active
August 5, 2016 03:22
-
-
Save preco21/382f86c062c29b778dc6035c88caf1a2 to your computer and use it in GitHub Desktop.
Benchmark various methods to copy array in ES2015
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
import {Suite} from 'benchmark'; | |
const suite = new Suite(); | |
suite | |
.add('Array Spread Operator', () => { | |
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; | |
const b = [...a]; | |
}) | |
.add('Array.from()', () => { | |
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; | |
const b = Array.from(a); | |
}) | |
.add('arr.slice()', () => { | |
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; | |
const b = a.slice(); | |
}) | |
.add('arr.concat()', () => { | |
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; | |
const b = a.concat(); | |
}) | |
.on('cycle', (event) => { | |
console.log(String(event.target)); | |
}) | |
.on('complete', () => { | |
console.log(`Winner: ${suite.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
Results:
OS: Windows 10
Node: 5.11.0