const ARRAY_SIZE = 15000576;  // 100 million items

function getTime() {
    return performance.now() / 1000; // returns time in seconds
}

function main() {
    const a = new Float32Array(ARRAY_SIZE);
    const b = new Float32Array(ARRAY_SIZE);
    const c = new Float32Array(ARRAY_SIZE);

    // Initialize arrays
    const start = getTime();
    for (let i = 0; i < ARRAY_SIZE; i++) {
        a[i] = i;
        b[i] = i * 2;
    }
    const initTime = getTime() - start;

    // Perform the calculation
    const startCalc = getTime();
    for (let i = 0; i < ARRAY_SIZE; i++) {
        c[i] = a[i] + b[i];
    }
    const calcTime = getTime() - startCalc;

    // Print timing results
    console.log(`Array initialization time: ${(initTime * 1000).toFixed(3)} ms`);
    console.log(`Calculation time:          ${(calcTime * 1000).toFixed(3)} ms`);
    console.log(`Total time:               ${((initTime + calcTime) * 1000).toFixed(3)} ms`);

    // Print a sample of the result
    for (let i = 0; i < 10; i++) {
        console.log(`c[${i}] = ${c[i]}`);
    }
}

main();