int function1(int a, int b, int c, int d, int e, int f, int g, int h, int n) {
for (int i=0; i
a = h + g;
b = a - h;
c = b + a;
d = c - b;
e = d + c;
f = e - d;
g = f + e;
h = g - f;
}
return h;
}
int function2(int a, int b, int c, int d, int e, int f, int g, int h, int n) {
for (int i=0; i
h = g - f;
g = f + e;
f = e - d;
e = d + c;
d = c - b;
c = b + a;
b = a - h;
a = h + g;
}
return h;
}
// This is just the main which does all of the running and printing out
// You should be able to understand this code, but it is not required for the lab
int main(void) {
// Variables
int a,b,c,d,e,f,g,h;
int res;
clock_t start, end;
int numiters = 100000000;
// Benchmark function1
a = 1;
b = 1;
c = 1;
d = 1;
e = 1;
f = 1;
g = 1;
h = 1;
start = clock();
res = function1(a,b,c,d,e,f,g,h,numiters);
end = clock();
double seconds = (end - start)/((double)CLOCKS_PER_SEC);
printf("function1 (%d iterations):\n", numiters);
printf("\tThe result of the function is: %d\n", res);
printf("\ttime: %f seconds\n",seconds);
printf("\n");
// Benchmark function2
a = 1;
b = 1;
c = 1;
d = 1;
e = 1;
f = 1;
g = 1;
h = 1;
start = clock();
res = function2(a,b,c,d,e,f,g,h,numiters);
end = clock();
seconds = (end - start)/((double)CLOCKS_PER_SEC);
printf("function2 (%d iterations):\n", numiters);
printf("\tThe result of the function is: %d\n", res);
printf("\ttime: %f seconds\n",seconds);
printf("\n");
return 0;
}