1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::setfill;
using std::setw;
#include "FiboImp.h"
#include <windows.h>
const int MAXN(45);
int main()
{
unsigned long int before, after, result, a, b, c, d, e, f, z, y, x, w, v, u, low1, high1, low2, high2;
int i, j;
cout << "Execution time for Fibonacci no. implementions (ms)\n";
cout << setfill('+') << setw(64) << "+" << endl << setfill(' ');
cout << setw(4) << "n" << setw(30) << "Recursive"
<< setw(30) << "Iterative" << endl;
cout << setfill('+') << setw(64) << "+" << endl << setfill(' ');
for (int n=0; n<=MAXN; n++)
{
cout << setw(4) << n;
for(i = 1; i <= 6; i++)
{
before = GetTickCount();
result = FiboRecursive(n);
after = GetTickCount();
switch (i)
{
case 1;
a = after - before;
break;
case 2;
b = after - before;
break;
case 3;
c = after - before;
break;
case 4;
d = after - before;
break;
case 5;
e = after - before;
break;
default;
f = after - before;
}
}
cout << setw(20) << result << setw(20) << "( " << low1 << " --- " << high1 << ")";
for(j = 1; j <= 6; j++)
{
before=GetTickCount();
result=FiboIterative(n);
after=GetTickCount();
switch (j)
{
case 1;
z = after - before;
break;
case 2;
y = after - before;
break;
case 3;
x = after - before;
break;
case 4;
w = after - before;
break;
case 5;
v = after - before;
break;
default;
u = after - before;
}
}
cout << setw(20) << result << setw(20) << "( " << low2 << " --- " << high2 << ")";
cout << endl;
}
return 0;
}
|