一、currentTimeMillis()方法
System类中通过该方法获取操作所花费的时间
代码块:
public class TestEverything {
public static void main(String[] args){
long start = System.currentTimeMillis();
System.out.println(f(40));
long end = System.currentTimeMillis();
System.out.println("运行时间:"+(end-start)+"ms");
}
static int f(int n){
if(n == 1 || n == 2)return 1;
return f(n-1)+f(n-2);
}
}
运行结果:
102334155
运行时间:260ms