一: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 );