#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define ARRAY_SIZE 15000576  // 100 million items

double get_time() {
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec + tv.tv_usec * 1e-6;
}

int main() {
    float *a = (float*)malloc(sizeof(float) * ARRAY_SIZE);
    float *b = (float*)malloc(sizeof(float) * ARRAY_SIZE);
    float *c = (float*)malloc(sizeof(float) * ARRAY_SIZE);

    // Initialize arrays
    double start = get_time();
    for (int i = 0; i < ARRAY_SIZE; i++) {
        a[i] = i;
        b[i] = i * 2;
    }
    double init_time = get_time() - start;

    // Perform the calculation
    start = get_time();
    for (int i = 0; i < ARRAY_SIZE; i++) {
        c[i] = a[i] + b[i];
    }
    double calc_time = get_time() - start;

    // Print timing results
    printf("Array initialization time: %.3f ms\n", init_time * 1000);
    printf("Calculation time:          %.3f ms\n", calc_time * 1000);
    printf("Total time:               %.3f ms\n", (init_time + calc_time) * 1000);

    // Print a sample of the result
    for (int i = 0; i < 10; i++) {
        printf("c[%d] = %f\n", i, c[i]);
    }

    // Clean up
    free(a);
    free(b);
    free(c);

    return 0;
}
