Last active
November 4, 2018 07:51
-
-
Save ndabAP/59566ecf30b48981a2176ea50aafb151 to your computer and use it in GitHub Desktop.
Untyped vs. typed JavaScript Arrays
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 { performance } = require('perf_hooks') | |
const start = performance.now() | |
const buffer = new ArrayBuffer(393216) | |
let uInt32View = new Uint32Array(buffer) | |
const length = uInt32View.length | |
for (let i = 0; i < length; i++) { | |
uInt32View[i] = i | |
} | |
const end = performance.now() | |
console.log(uInt32View.length) | |
console.log(uInt32View[uInt32View.length - 1]) | |
console.info(end - start) // ~1.569806999526918 |
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 { performance } = require('perf_hooks') | |
const start = performance.now() | |
let untypedArray = [] | |
for (let i = 0; i < 98304; i++) { | |
untypedArray[i] = i | |
} | |
const end = performance.now() | |
console.log(untypedArray.length) | |
console.log(untypedArray[untypedArray.length - 1]) | |
console.info(end - start) // ~2.792820000089705 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment