Created
July 19, 2017 16:51
-
-
Save stormslowly/ba5cba0a519bff98030f52835ef3e0c6 to your computer and use it in GitHub Desktop.
generate array contains 1 to 1e7
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
console.time("Array.push"); | |
const array = []; | |
for (var i = 0; i < 1e7; i++) array[i] = i; | |
console.timeEnd("Array.push"); | |
console.time("new Array.push"); | |
const array1 = new Array(1e7); | |
for (var i = 0; i < 1e7; i++) array1[i] = i; | |
console.timeEnd("new Array.push"); | |
console.time("new Array.push rev"); | |
const array2 = new Array(1e7); | |
for (var i = 1e7-1; i>=0; i--) array2[i] = i; | |
console.timeEnd("new Array.push rev"); | |
console.time("Array.map"); | |
const array3 = [ ...Array(1e7).keys() ].map((_, i) => i); | |
console.timeEnd("Array.map"); | |
console.time("Array.from"); | |
const array4 = Array.from({length:1e7},(_, i) => i); | |
console.timeEnd("Array.from"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment