/*很无聊写着玩玩,后来发现memset效率会比fill高出这么多,可惜一般只用来赋值0,-1.。。。。。以后可以用fill来偷偷懒了。。。*/
#include<iostream>
#include<ctime>
using namespace std;
#define max 100000000+5
int a[max];
int main()
{
time_t beg,end;
beg=clock();
cout<<"---------------------------for
";
for(int i=0;i<max;i++)
{
a[i]=0;
}
end=clock();
cout<<"test 1 cost: "<<end-beg<<"MS"<<endl;
for(int i=0;i<max;i++)
{
a[i]=0;
}
end=clock();
cout<<"test 2 cost: "<<end-beg<<"MS"<<endl;
for(int i=0;i<max;i++)
{
a[i]=0;
}
end=clock();
cout<<"test 3 cost: "<<end-beg<<"MS"<<endl;
for(int i=0;i<max;i++)
{
a[i]=0;
}
end=clock();
cout<<"test 4 cost: "<<end-beg<<"MS"<<endl;
for(int i=0;i<max;i++)
{
a[i]=0;
}
end=clock();
cout<<"test 5 cost: "<<end-beg<<"MS"<<endl;
for(int i=0;i<max;i++)
{
a[i]=0;
}
end=clock();
cout<<"test 6 cost: "<<end-beg<<"MS"<<endl;
cout<<"---------------------------fill
";
beg=clock();
fill(a,a+max,0);
end=clock();
cout<<"test 1 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
fill(a,a+max,0);
end=clock();
cout<<"test 2 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
fill(a,a+max,0);
end=clock();
cout<<"test 3 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
fill(a,a+max,0);
end=clock();
cout<<"test 4 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
fill(a,a+max,0);
end=clock();
cout<<"test 5 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
fill(a,a+max,0);
end=clock();
cout<<"test 6 cost: "<<end-beg<<"MS"<<endl;
cout<<"---------------------------memset
";
beg=clock();
memset(a,0,sizeof(a));
end=clock();
cout<<"test 1 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
memset(a,0,sizeof(a));
end=clock();
cout<<"test 2 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
memset(a,0,sizeof(a));
end=clock();
cout<<"test 3 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
memset(a,0,sizeof(a));
end=clock();
cout<<"test 4 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
memset(a,0,sizeof(a));
end=clock();
cout<<"test 5 cost: "<<end-beg<<"MS"<<endl;
beg=clock();
memset(a,0,sizeof(a));
end=clock();
cout<<"test 6 cost: "<<end-beg<<"MS"<<endl;
}