java - How to use the execution time method with try and catch -
i trying measure execution time, not know method before try block or inside??
ublic static void main(string[] args) { long starttime = system.currenttimemillis(); try { searchdetailsdialog dialog = new searchdetailsdialog(null); dialog.setdefaultcloseoperation(jdialog.dispose_on_close); dialog.setvisible(true); } catch (exception e) { e.printstacktrace(); }long endtime = system.currenttimemillis(); long totaltime = ((endtime - starttime)/1000); system.out.println("the execution time is:"); system.out.println(totaltime); }
neither. in case best is:
long starttime= system.nanotime() ; try { searchdetailsdialog dialog = new searchdetailsdialog(null); dialog.setdefaultcloseoperation(jdialog.dispose_on_close); dialog.setvisible(true); } catch (exception e) { e.printstacktrace(); } { long endtime= system.nanotime() ; double totaltime= ((double)(endtime - starttime)/1000000000) ; system.out.printf("the execution time is: %.3f seconds",totaltime); }
Comments
Post a Comment