Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Please tell me..How to find the time taken by a method in Java program?  RSS feed

 
Madhu Kumar Vatts
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I want to print the time taken by a particular method in a java program. What API has this feature. Appreciate your time in replying.

Thanks
Madhu
 
Matt Fielder
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
couldn't you just timestamp the start and stop times then compare the two?
Since the number would be so small, have it iterate 1000 times.
 
Madhu Kumar Vatts
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the answer...I used java.lang.System.currentTimeMillis().
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/time/StopWatch.html which is a little bit less low level...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!