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; }
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; }
闲来无事写写代码,消磨time。。。。。