SIMD test
by evgkch
Babel + JSX
const createArray = (length) => Array.from( {length: length}, (v) => Math.round(Math.random() * 1000) / 1000);
const test = (n) => (fn) => {
let start = new Date().getTime();
for(let i = 0; i < n; i++) {
fn()
}
let finish = new Date().getTime();
return console.log(`Work time: ${Math.round(finish - start)} msec`)
}
const fnScalar = () => {
let a = createArray(4);
let b = createArray(4);
let c = [];
c[0] = a[0] + b[0];
c[1] = a[1] + b[1];
c[2] = a[2] + b[2];
c[3] = a[3] + b[3];
return c;
}
const fnVector = () => {
let a = SIMD.Float32x4(createArray(4));
let b = SIMD.Float32x4(createArray(4));
let c = SIMD.Float32x4.add(a, b);
}
let _test = test(10000);
_test(fnScalar);
_test(fnVector);