zoukankan      html  css  js  c++  java
  • 测试代码的运行时间(经典加总结)

    C++版测试代码运行时间(第一种方法)

    # include<iostream>
    # include<ctime>
    # include<cstdlib>
    # include<algorithm>
    # include<cstdio>
    using namespace std;
    int main()
    {
        srand((unsigned)time(0));
       //freopen("d:\A.in","r",stdin);
        //freopen("d:\A.out","r",stdout);
        int begin,end;
        begin=clock();
    
        int a,b;
        scanf("%d %d",&a,&b);
        int c = a+b;
        printf("%d",c);
    
        end=clock();
        cout<<"runtime: "<<double(end-begin)/CLOCKS_PER_SEC<<endl;
    }
    View Code

    C++版测试代码运行时间(第二种方法)

    # include<iostream>
    # include<ctime>
    # include<cstdlib>
    # include<algorithm>
    # include<cstdio>
    using namespace std;
    int main()
    {
        srand((unsigned)time(0));
        //freopen("d:\A.in","r",stdin);
        //freopen("d:\A.out","r",stdout);
        time_t begin,end;
        begin=clock();
    
        int a,b;
        scanf("%d %d",&a,&b);
        int c = a+b;
        printf("%d",c);
    
       end=clock();
        cout<<"runtime: "<<double(end-begin)/CLOCKS_PER_SEC<<endl;
    }
    View Code

    闲来无事写写代码,消磨time。。。。。

  • 相关阅读:
    自制凉皮
    牛人
    史记
    阅读detection
    最近的购书清单
    不要轻易挑战用户的习惯,否则会被用户打脸!
    INVEST原则的应用
    谈谈Backlog梳理活动
    要写封闭式的用户故事
    敏捷教练的八种失败角色
  • 原文地址:https://www.cnblogs.com/sxmcACM/p/3303140.html
Copyright © 2011-2022 走看看