fill memset, for小测试
/*很无聊写着玩玩,后来发现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\n";
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\n";
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\n";
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;
}
posted on 2013-07-10 11:27 Stomach_ache 阅读(188) 评论(0) 编辑 收藏 举报