int main(){
int texttimes = TEXT_TIMES;
m = 50;
while(texttimes--){
int size,choice;
cout<<"请输入你要运行的大整数的位数:"<<endl;
cin>>size;
cout<<"请选择你需要的方法(1、普通法;2、分治法)"<<endl;
cin>>choice;
double random(double,double);
srand(unsigned(time(0)));
double sumtime = 0;
int t = TIMES; //定义测试的次数
while(t--){
string a,b;
for(int i = 0; i<size; i++){
a += itoc(int(random(0,9)));
b += itoc(int(random(0,9)));
}
clock_t start_time=clock(); //开始时间
if(choice == 1)
tramul(a,b); //调用普通大整数乘法
else if(choice == 2)
mul(a,b); //调用基于分治法的大整数乘法
clock_t end_time=clock(); //结束时间
sumtime += static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000;
}
cout<<"运行"<<TIMES<<"次的总时间为:"<<sumtime<<"ms"<<endl<<"平均运行时间为:"<<sumtime/TIMES<<"ms"<<endl;
}
int texttimes = TEXT_TIMES;
m = 50;
while(texttimes--){
int size,choice;
cout<<"请输入你要运行的大整数的位数:"<<endl;
cin>>size;
cout<<"请选择你需要的方法(1、普通法;2、分治法)"<<endl;
cin>>choice;
double random(double,double);
srand(unsigned(time(0)));
double sumtime = 0;
int t = TIMES; //定义测试的次数
while(t--){
string a,b;
for(int i = 0; i<size; i++){
a += itoc(int(random(0,9)));
b += itoc(int(random(0,9)));
}
clock_t start_time=clock(); //开始时间
if(choice == 1)
tramul(a,b); //调用普通大整数乘法
else if(choice == 2)
mul(a,b); //调用基于分治法的大整数乘法
clock_t end_time=clock(); //结束时间
sumtime += static_cast<double>(end_time-start_time)/CLOCKS_PER_SEC*1000;
}
cout<<"运行"<<TIMES<<"次的总时间为:"<<sumtime<<"ms"<<endl<<"平均运行时间为:"<<sumtime/TIMES<<"ms"<<endl;
}