2

I have a bit of an interesting question here about performance and was wondering if there was any way to do what I want to do:

I'm dealing with a large code-base (10,000+ lines), I want to run the code and get a visual analysis of what lines takes up the most time in the code. Like for example, is there anything that can highlight the lines of code that take up the longest amounts of time in .NET and/or give you a time spent on each line? In my mind, I'm visualizing something simple, like a green, yellow, and red highlight for each line of code and perhaps an amount of time that tells you how long each line took to run.

One way to get times would be through the Stopwatch, but its such a pain to have to have to add Stopwatches over and over again. How could I go about profiling my codebase like this? Does Visual Studio or .NET have anything out of the box for this?

Edit: Thanks to Patrick, I found out about ANTS, which does exactly what I wanted above (also shows HOT! lines in red in another window - lines that take up the most time...FYI: this isn't a profiler advertisement; I just required a line-by-line profiler for my needs and this does the trick so take it or leave it):

enter image description here

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • Search for [profiles .net applications](https://www.google.ca/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=profiles%20.net%20applications) – Habib Oct 22 '14 at 14:04
  • There are tons of code profilers out there. Pick one (or more) and try them out. – Servy Oct 22 '14 at 14:04
  • Yes, but like I've said above, is there one that goes line-by-line? I don't care about library calls, and other garbage information. – Alexandru Oct 22 '14 at 14:15
  • this is a valid question. please vote to reopen – Boppity Bop Apr 10 '21 at 10:39

1 Answers1

2

It's called a profiler, and there are many of them.

Some Visual Studio versions come with built-in analysis tools. Another tool I commonly use is ANTS Performance Profiler.

They sample which method is active (sampling), or even collect info on a per line / statement basis (instrumentation), depending on the settings used. You can use that to check what lines are most commonly used, or what lines consume most time each.

As a sample, take a look at the images in my question regarding statistics acquired from profiling.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
  • Thanks Patrick, I will check it out. I'm not sure why my question had such a negative response. – Alexandru Oct 22 '14 at 14:21
  • 2
    @Alexandru: your question as originally formulated and titled gave the appearance that you had no clue at all what a profiler is, and SO users tend to be quite hostile towards ignorance -- which is unfortunate for a site about answering questions, but there you go. – Jeroen Mostert Oct 22 '14 at 14:24
  • 1
    @JeroenMostert Very well said. – Alexandru Oct 22 '14 at 14:25
  • Patrick, ANTS is amazing, just tried it out. Its expensive to buy, but this is EXACTLY what I was looking for! – Alexandru Oct 22 '14 at 14:32
  • 1
    @Alexandru: Glad it helped. Read the question referenced in my answer as a warning. If you use detailed analysis, it will slow down your app very much, making the metrics seem very high, but most of it is caused by the profiler itself. Don't let it fool you, like it did me. – Patrick Hofman Oct 22 '14 at 14:35