Created
August 29, 2017 04:45
-
-
Save CodeMan99/18d590d12aef1e90d2ed262f4fab0c96 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
function arrayFrom(a) { | |
return Array.from(arguments).slice(1); | |
} | |
function arraySlice(a) { | |
return Array.prototype.slice.call(arguments, 1); | |
} | |
function argsRest(a, ...args) { | |
return args; | |
} | |
function argsSpread(a) { | |
return [...arguments].slice(1); | |
} | |
function forArgs(a) { | |
var len = arguments.length; | |
var args = new Array(len - 1); | |
for (var i = 0; i < len; ++i) { | |
args.push(arguments[i]); | |
} | |
return args; | |
} | |
var i; | |
i = 0; | |
console.time('Array.from'); | |
while (i++ < 1000000) { | |
arrayFrom(i, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'); | |
} | |
console.timeEnd('Array.from'); | |
i = 0; | |
console.time('Array.prototype.slice.call'); | |
while (i++ < 1000000) { | |
arraySlice(i, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'); | |
} | |
console.timeEnd('Array.prototype.slice.call'); | |
i = 0; | |
console.time('...args rest'); | |
while (i++ < 1000000) { | |
argsRest(i, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'); | |
} | |
console.timeEnd('...args rest'); | |
i = 0; | |
console.time('...args spread'); | |
while (i++ < 1000000) { | |
argsSpread(i, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'); | |
} | |
console.timeEnd('...args spread'); | |
i = 0; | |
console.time('for (;;)'); | |
while (i++ < 1000000) { | |
forArgs(i, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'); | |
} | |
console.timeEnd('for (;;)'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: