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。。。。。

  • 相关阅读:
    [loj6484]LJJ爱数书
    [loj3163]动态直径
    [loj2983]数树
    [luogu3785]文本校正
    [loj2572]字符串
    [loj3103]节日庆典
    [atARC118F]Growth Rate
    [atARC118E]Avoid Permutations
    [cf794G]Replace All
    [cf756E]Byteland coins
  • 原文地址:https://www.cnblogs.com/sxmcACM/p/3303140.html
Copyright © 2011-2022 走看看