Last active
May 2, 2017 06:02
-
-
Save trickpattyFH20/7a907a2a24a7a4341f6f8bd953333855 to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
var Benchmark = require('benchmark'); | |
var suite = new Benchmark.Suite; | |
// add tests | |
suite | |
.add('for', function() { | |
const a = [1, 2, 3]; | |
const b = [4, 5, 6]; | |
// optimized for loop | |
const len = b.length; | |
for(let i = 0; i < len; i++) { | |
a.push(b[i]); | |
} | |
}) | |
.add('forOf', function() { | |
const a = [1, 2, 3]; | |
const b = [4, 5, 6]; | |
for(let val of b) { | |
a.push(val); | |
} | |
}) | |
.add('pushApply', function() { | |
const a = [1, 2, 3]; | |
const b = [4, 5, 6]; | |
Array.prototype.push.apply(a, b); | |
}) | |
.add('pushSpread', function() { | |
const a = [1, 2, 3]; | |
const b = [4, 5, 6]; | |
a.push(...b); | |
}) | |
.add('concat', function() { | |
const a = [1, 2, 3]; | |
const b = [4, 5, 6]; | |
const c = a.concat(b); | |
}) | |
.on('cycle', function(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