I want to record the time taken by my Java program. Most forums suggest something like:
int starttime=System.nanoTime();
//program code
int endTime=System.nanoTime();
int timetaken=starttime-endTime;
The problem with this approach is that if there are multiple programs running, then the difference between endTime and starttime is not the time taken by my program. It is also the time taken during scheduling of different programs in the CPU etc. However, I am only interested to record the time taken by my program. How do I get this time?