如何計算java程序運行花了多長時間。加時間戳。


 

1 long start = System.currentTimeMillis(); // 記錄起始時間
2 try { 
3      Thread.sleep(5000);                     // 線程睡眠5秒,讓運行時間不那么小
4    } catch (InterruptedException e) {
5             e.printStackTrace();
6        }
7 long end = System.currentTimeMillis();       // 記錄結束時間
8 System.out.println(end-start);              // 相減得出運行時間

單位是毫秒。

long start = System.currentTimeMillis(); //獲取當前時間

long end = System.currentTimeMillis();  

 

//System.nanoTime()   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM