Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to profile line-by-line in .NET? [closed]

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

like image 819
Alexandru Avatar asked Dec 14 '25 03:12

Alexandru


1 Answers

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.

like image 182
Patrick Hofman Avatar answered Dec 15 '25 16:12

Patrick Hofman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!