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 time of execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "time of execution " Watch "time of execution " New topic

time of execution

Puneet N Vyas
Ranch Hand

Joined: Sep 20, 2007
Posts: 61
i have used time of execution class to know the time of execution of the operation,but upon running the program different times it gives different time of execution,can any one tell why it is happening or anyother way to get the time of execution

thanks for support
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
How big a difference are you seeing in the times ? No program will have the same execution time every time it runs.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15084

Note that the accuracy of the timer used by System.currentTimeMillis() is not very good on some operating systems. So if you time very short events, you will not get very accurate time measurements if you use this.

If you're using Java 5 or newer, you could use System.nanoTime() instead, which will probably use a more accurate timer, but even that timer does not have a guaranteed accuracy.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
The time of execution should not be expected to be a constant.

If you're playing video on your machine, and defragging the hard drive, it will effect other processes. All machines are running many, many processes, and they're all sharing the resources.

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: time of execution
It's not a secret anymore!