运行时间

来源:互联网 发布:特种兵小说 知乎 编辑:程序博客网 时间:2024/04/29 00:23
public class Time{
 private long start,end;
 public void testFor(){
 start = System.nanoTime();
 for(int i = 1,sum = 0;i<=100;i++)
 sum += i;
 end = System.nanoTime();
 }
 public long getUsedTime(){
 testFor();
 return end-start;
 }
 public static void main(String args[]){
 NanoTime testFor = new NanoTime();
 System.out.println(testFor.getUsedTime());
 }
 }
原创粉丝点击