• 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 ";
     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;
    }

  • 相关阅读:
    名门暗战
    redis安装相关下载
    Git:git diff 命令详解
    【教程】Win7-64位安装OpenSSL详细过程
    Linux 下MQ的安装和配置亲测
    用命令创建MySQL数据库
    WebSphere MQ中的CCSID
    Netty:option和childOption参数设置说明
    BeanNameAware接口和BeanFactoryAware接口
    再理解tcp backlog
  • 原文地址:https://www.cnblogs.com/Stomach-ache/p/3703273.html
Copyright © 2020-2023  润新知