• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get Thread execution time ?

 
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I want to find out the time Mycode portion has taken to execute. I used the above function to find this out. But I am not sure whether the duration I get is the time taken by this portion alone or does it include the total time taken from start to finish which may include time taken by other processes and background jobs running in my computer. In other words I want the time taken by Mycode portion to execute in the absence of all other system processes. Is this the correct function to use or is there any other function to achieve that?
 
Saloon Keeper
Posts: 15510
363
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not 100% sure, but I think that's a correct way to make a best effort time measurement for a specific thread, excluding the time that other treads take in the mean time. However, it includes the time that the thread has spent in system space (calls to the kernel). If you only want the time it has spent inside your application, you should use getThreadUserTime().

Note that ThreadMXBean has getCurrentThreadCpuTime() and getCurrentThreadUserTime(), which are more convenient to call than what you're doing.
 
Akshay Rathore
Greenhorn
Posts: 17
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for the help.
reply
    Bookmark Topic Watch Topic
  • New Topic