Last active
August 17, 2017 05:21
-
-
Save justjavac/352fafd93b060ffb5cbe87064d8f46f7 to your computer and use it in GitHub Desktop.
TypedArray 性能 http://weibo.com/1361535293/Fhvl8vmvh
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 test() { | |
const a = new Int32Array(10); | |
for (let i = 0; i < 1e6; i++) { | |
a.set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | |
} | |
return a; | |
} | |
console.time('test'); | |
test(); | |
console.timeEnd('test'); | |
new Int8Array(1).set([0]); | |
new Uint8Array(1).set(['5']); | |
new Float32Array(1).set([NaN]); | |
new Float64Array(1).set([0.1]); | |
console.time('test'); | |
test(); | |
console.timeEnd('test'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The type feedback for the relevant internal function TypedArraySetFromArrayLike is polluted.
https://github.com/v8/v8/blob/e08cdc277ba089ca6ff01682eb877af9b1cdec38/src/js/typedarray.js#L254-L265