|
|
#include <iostream>
|
|
|
using namespace std;
|
|
|
#include "Benchmark.h"
|
|
|
#include "Timer.h"
|
|
|
#include "YourFib.h"
|
|
|
#include <stdlib.h>
|
|
|
int main()
|
|
|
{
|
|
|
//测试Fib类
|
|
|
int n;
|
|
|
cout << "请输入2阶斐波那契数列的项数n:";
|
|
|
cin >> n;
|
|
|
Fib fib(n); //定义一个用于测试Fib类的对象
|
|
|
fib.Value(fib.GetN(n)); //计算2阶斐波那契数列第n项的值
|
|
|
cout << "Fib(" << n << ")=" << fib.GetValue() << endl
|
|
|
<< endl
|
|
|
<< endl; //输出2阶斐波那契数列第n项的值
|
|
|
//测试Partition操作
|
|
|
benchmark_hw1_4(5, 600, 5, 200);
|
|
|
return 0;
|
|
|
// void timePartition(FILE *fp, int incN, int maxN, int numTrials, char *partitionAlg); //函数声明
|
|
|
int incN = 5; //设置数组初始长度
|
|
|
int maxN = 600;
|
|
|
int numTrials = 200; //测试次数
|
|
|
char partitionAlg[20] = "Partition"; //算法的名称
|
|
|
char outFileName[20]; //测试结果存放的文件名
|
|
|
FILE *fp;
|
|
|
errno_t err;
|
|
|
//创建一个名为partitionAlg[i].txt的文件
|
|
|
strcpy_s(outFileName, partitionAlg);
|
|
|
strcat_s(outFileName, ".txt");
|
|
|
err = fopen_s(&fp, outFileName, "a+");
|
|
|
printf("# Results for %d 次测试", numTrials);
|
|
|
printf("# n time (msec)");
|
|
|
printf("# ---------------\n");
|
|
|
//统计partitionAlg[i]算法对大小为incN,2*incN,3*incN,...,maxN的数组进行一次划分的时间
|
|
|
//timePartition(fp, incN, maxN, numTrials);
|
|
|
fclose(fp);
|
|
|
printf("done! results in %s\n\n\n\n", partitionAlg);
|
|
|
system("pause");
|
|
|
} |