计算运行时间

一:c++版本

clock():捕捉从程序运行开始到clock()被调用时所耗费的时间。这个时间单位是clock tick,即“时钟打点”。
常数CLK_TCK : 机器时钟每秒所走的时钟打点数

#include<bits/stdc++.h> 
using namespace std;
clock_t start,stop;
double duration;
int main() {
	start = clock();
	cout<<"nihao "<<endl;
	stop = clock();
	duration = (double)(stop - start) / CLK_TCK;
	cout<<duration;
}

——————————————————————————————————

二:Java

        long startTime = System.nanoTime();
		System.out.println("=========================="); 
	    for(Integer item : al)
	    {
	    	;
	    }
		long endTime = System.nanoTime();
	    long duration = endTime - startTime;
	    System.out.println(duration );
发布了4 篇原创文章 · 获赞 0 · 访问量 66

猜你喜欢

转载自blog.csdn.net/m0_46177657/article/details/104359586