Posted on 2014-02-14 09:51
ZT文萃 閱讀(209)
評(píng)論(0) 編輯 收藏 所屬分類:
中間件
http://blog.163.com/kevinlee_2010/blog/static/16982082020112710557998/
第一種是以毫秒為單位計(jì)算的。
Java代碼
//偽代碼
long startTime=System.currentTimeMillis(); //獲取開始時(shí)間
doSomeThing(); //測(cè)試的代碼段
long endTime=System.currentTimeMillis(); //獲取結(jié)束時(shí)間
System.out.println("程序運(yùn)行時(shí)間: "+(end-start)+"ms");
//偽代碼
long startTime=System.currentTimeMillis(); //獲取開始時(shí)間
doSomeThing(); //測(cè)試的代碼段
long endTime=System.currentTimeMillis(); //獲取結(jié)束時(shí)間
System.out.println("程序運(yùn)行時(shí)間: "+(end-start)+"ms");
第二種是以納秒為單位計(jì)算的。
Java代碼
//偽代碼
long startTime=System.nanoTime(); //獲取開始時(shí)間
doSomeThing(); //測(cè)試的代碼段
long endTime=System.nanoTime(); //獲取結(jié)束時(shí)間
System.out.println("程序運(yùn)行時(shí)間: "+(end-start)+"ns");
//偽代碼
long startTime=System.nanoTime(); //獲取開始時(shí)間
doSomeThing(); //測(cè)試的代碼段
long endTime=System.nanoTime(); //獲取結(jié)束時(shí)間
System.out.println("程序運(yùn)行時(shí)間: "+(end-start)+"ns");