File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes How i get execution time in java??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How i get execution time in java???" Watch "How i get execution time in java???" New topic

How i get execution time in java???

Muhammad usman shad
Ranch Hand

Joined: Jan 06, 2010
Posts: 30
Assalam o Aliekum to all,

I am assigned a task by my teacher in java in which i am sorting an array using different sortin techniques.

I do it accurately...


Now i have to get the Execution time from the system which it takes to get the output,

Is there any method in java which can do this and if not then can i do it???

If yes,

Then please please help me,
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Look at java.lang.System.currentTimeMillis() and build something around it.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Costi Ciudatu
Ranch Hand

Joined: Oct 24, 2006
Posts: 74
Also, if you simply instantiate a java.util.Date object with the default constructor (new Date()) that will reflect the current time.
The same applies to java.util.Calendar.getInstance().
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

And if milliseconds is not accurate enough, Java 5.0 added System.nanoTime() which returns the time in nanoseconds.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: How i get execution time in java???
It's not a secret anymore!