6

I have got stucked where one of my function is taking some time to execute. I have a hierarchy of objects in object using object models and ArrayList(s). I just want to know the techniques by which I can debug the code to check which statement of code is taking time in execution.

Aashutosh Sharma
  • 1,483
  • 2
  • 17
  • 29

2 Answers2

15

Simply use this.

long startTime = System.nanoTime();
YourMethode();
long endTime = System.nanoTime();

long MethodeDuration = (endTime - startTime);
Remees M Syde
  • 2,564
  • 1
  • 19
  • 42
  • Didn't you understand the problem? If you already know that one method is slow you win nothing by measuring it's execution time. With your code it would be VERY exhausting to check every line of the slow code. – The incredible Jan Jul 20 '17 at 14:20
4

Two solutions :

Community
  • 1
  • 1
mithrop
  • 3,283
  • 2
  • 21
  • 40
  • Get More details [here](https://stackoverflow.com/questions/180158/how-do-i-time-a-methods-execution-in-java) – Zia Jun 15 '17 at 06:21