0

I wrote an API with 1000 lines of code. In code somewhere it's taking more time, so response time is increasing. I have two questions here

  1. How can I find the execution time of each line of the code?
  2. How can I identify code taking more time?
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
nithin
  • 371
  • 9
  • 24
  • 1
    Use a Java performance profiler; see https://www.baeldung.com/java-profilers to learn more about this topic. – Stephen C Aug 29 '21 at 10:18
  • Here's a relevant StackOverflow Q&A - https://stackoverflow.com/questions/22250303 – Stephen C Aug 29 '21 at 10:19
  • 1
    Perhaps, you wrote some code with 1000 lines of code, but surely not an API. Further code is not executed line by line, so trying to identify a line’s share on execution time is pointless. – Holger Aug 30 '21 at 15:11

1 Answers1

1

Profiling ​is what you are looking for, it ​basically shows you how often a given line of code is executed and how much time was spent in it (compared to other lines). This makes it easy to pinpoint the location where your code spends most of the time.

IntelliJ IDEA Ultimate has out-of-the-box support for profiling your applications using multiple Profilers.​

Ref: https://blog.jetbrains.com/idea/2020/03/profiling-tools-and-intellij-idea-ultimate/​

rajnikant7008
  • 76
  • 2
  • 10