#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
const int N=100000;
void time_first() {
struct timeval start, mid, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
for(int j=0;j<N;j++){
arr1[j] += a1[j];
arr2[j] += a2[j];
}
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
printf("First elapsed time: %ld milliseconds\n", mtime);
}
void time_second() {
struct timeval start, mid, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
for(int j=0;j<N;j++){
arr1[j] += a1[j];
}
for(int j=0;j<N;j++){
arr2[j] += a2[j];
}
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
printf("Second elapsed time: %ld milliseconds\n", mtime);
}
int main() {
initialize arr1, a1 and a2
time_first();
time_second();
return 0;
}