2

I'm looking for a tool to tell me how long my code takes to run. Something that would be the equivalent of recording the DateTime.Now before and after each line of code in my program, then displaying the difference between the two times for each line (after my program finishes running).

For instance, if I have a program that calls four methods in its main, I want to know (after running this tool) how long each of those methods takes to run, and then if I stepped into each method, I'd want to know how long each line in there takes to run, and so on.

Do these tools exists? Of course I'd prefer a free one, but if all that exist are professional tools then please mention those as well.

edit: it appears these tools are called Profiling tools. Thanks, this will definitely help me in my search. Unfortunately, I'm using Visual Studio 2010 Professional, so I believe the Microsoft profiling tool is out of my grasp. Any good third-party profiling tools?

pghprogrammer4
  • 898
  • 2
  • 9
  • 21
  • 2
    Re: DateTime.Now - look into Stopwatch class :) - http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx – Daniel Mošmondor Jul 05 '11 at 20:28
  • If you just want to measure, that's one thing. If you want to locate your time-drains so you can fix them to gain speed, there's a [very simple effective technique](http://stackoverflow.com/questions/2473666/tips-for-optimizing-c-net-programs/2474118#2474118). – Mike Dunlavey Jul 06 '11 at 01:21

5 Answers5

4

You can use the CLR Profiler for .NET Framework 4

The CLR Profiler includes a number of very useful views of the allocation profile, including a histogram of allocated types, allocation and call graphs, a time line showing GCs of various generations and the resulting state of the managed heap after those collections, and a call tree showing per-method allocations and assembly loads.

And even more profilers and tools can be found here...

More about profiling on the wikipedia

Caspar Kleijne
  • 21,552
  • 13
  • 72
  • 102
3

If you use the Profiler tool that come with VS it shows this to you very well. Only one down side is that I think it only comes with Ultimate. :(

Jethro
  • 5,896
  • 3
  • 23
  • 24
1

Are you looking for the performance profiler? It tells you how long each function takes.

user541686
  • 205,094
  • 128
  • 528
  • 886
0

I like dotTrace, it's by the same guys that make Resharper: dotTrace

Kelly
  • 6,992
  • 12
  • 59
  • 76
0

Give a try to Red Gate ANTS Performance Profiler. There's a free trial, and if you don't have access to the built-in VS2010 profiler, it does a good job.

Matthieu
  • 4,605
  • 4
  • 40
  • 60