4

I am completely new to the idea of profiling, can anyone give me simple steps on how I would profile a specific function?

Both functions do the same thing, but one is in C# in vs2008, the other C++ in vs2010. I'm really mostly interested in the C++ function as it is being incredibly slow and I want to find out where/why. Thanks.

Dollarslice
  • 9,917
  • 22
  • 59
  • 87

2 Answers2

3

simple steps on how I would profile a specific function

The method I use is random pausing, maybe better known as the poor man's profiler (which I liked until I saw how they aggregate). Here's another link. You don't have to tell it what specific function to look at. It automatically finds what takes the most time, whether it's that function or another one.

The thing about it is, compared to "real" profilers, some might say it is crude, tedious, etc. So why do it?

Because it's effective.

You nail your problem, down to specific instructions, and know what to fix, before you even begin to puzzle through the reams of stuff that comes out of most profilers - self time, call counts, call trees, call graphs, "hot paths", "cpu time", etc. etc..

The thing to ask of any profiler is not how "accurate" it is, but

  • How much speedup is typically achieved by using it, in real (not toy) programs?

Isn't that what you care about?

Here's an example of a 43x speedup done with random-pausing.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
1

Here is one idea. Write a test app that calls this function repeatedly and does as little else as possible. Then create two executables with the two versions of your function. Now run the Very Sleepy profiler on both executables, and compare the results. The profiler will show you what the slow parts of each function are.

Another profiler that you may find useful is Shiny. It works in a completely different way. You have to insert calls in the functions or sections of code you want to profile, and then compile a special profiler enabled version of your app.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
  • can you not profile specific bits within a program or do you always have to create a mini program with the part of interest in? – Dollarslice Oct 19 '11 at 08:03
  • This specific profile does not require instrumentation of your app, it just profiles the apps as it runs natively. So it will profile the whole thing. There are other profilers that require you to instrument your code, for those you can only profile one function in your app. I'm updating my answer with a link to another profiler that requires instrumentation. – Miguel Grinberg Oct 19 '11 at 15:34