Monday, August 07, 2006

How to calculate execution time

Execution time is a very important measure to evaluate the system performance. The execution time can be computed by reduce the ending time using the starting time of the program.
But how to get the starting and ending time?
I'm used to imagine a solution and check it in Java API. So it's very natural for me to consider the Date class. But unfortunately, Date does not provide a static method for us to get the current time. So I have to create a new Date object whenever I want to retrieve the point of time. I've always been very curious about why Java does not provide a static method.
Today, I happened to find another method to get such a time in a book. The System object has a static method called currentTimeMillis(), which returns the current system time. I finally realize that I have used the previous stupid method for so long!

No comments: