Last active
February 21, 2017 13:12
-
-
Save alexanderwallin/0bf6a2a6c88186ec68de5f42f88a9fa1 to your computer and use it in GitHub Desktop.
Does this have side effects?
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
export const readUint16 = (typedArr, offset) => { | |
const buf = new ArrayBuffer(2) | |
const uint8 = new Uint8Array(buf) | |
const uint16 = new Uint16Array(buf) | |
uint8[0] = typedArr[offset] | |
uint8[1] = typedArr[offset + 1] | |
return uint16[0] | |
} |
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
const buf = new ArrayBuffer(16) | |
const uint8 = new Uint8Array(buf) | |
const uint16 = new Uint16Array(buf) | |
export const readUint16 = (typedArr, offset) => { | |
uint8[0] = typedArr[offset] | |
uint8[1] = typedArr[offset + 1] | |
return uint16[0] | |
} |
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
const data = new Uint8Array(8) | |
data[0] = Math.pow(2, 0) | |
data[1] = Math.pow(2, 1) | |
data[2] = Math.pow(2, 2) | |
data[3] = Math.pow(2, 3) | |
data[4] = Math.pow(2, 4) | |
data[5] = Math.pow(2, 5) | |
data[6] = Math.pow(2, 6) | |
data[7] = Math.pow(2, 7) | |
console.time('letsgo') | |
for (let i = 0; i < 1000000; i++) { | |
readUInt8(data, 0) | |
readUInt16(data, 0) | |
readUInt32(data, 0) | |
readUInt8(data, 7) | |
readUInt16(data, 6) | |
readUInt32(data, 4) | |
readFloat32(data, 0) | |
readFloat32(data, 4) | |
readFloat64(data, 0) | |
} | |
console.timeEnd('letsgo') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment