Learning about typed arrays, I read typed arrays normally should be more efficient/performant than non-typed ones.
I run this simple test (replace a for b to run each test):
const a = [1, 2, 3, 4]
const b = new Uint8Array([1, 2, 3, 4])
const compare1 = (arr) => {
for (let i = 0; i < 4; i++) arr[i]
}
let run = 0
const init1 = performance.now()
while (run < 10e7) {
compare1(a)
run++
}
const finish1 = performance.now()
console.log("for a ", finish1 - init1)
const compare2 = (arr) => {
for (let i = 0; i < 4; i++) arr[i]
}
run = 0
const init2 = performance.now()
while (run < 10e7) {
compare2(b)
run++
}
const finish2 = performance.now()
console.log("for b ", finish2 - init2)
array contains mixed string and number types.
But maybe I am not getting some idea here...
Should those be expected to differ more? Example?
Edit: Added 2 different compareX functions.