From: Brian on
I've rewritten a slow Matlab code loop in C and it's already about 30x faster. I'd like to profile the C code that I've written to see how I can make it faster. How can I use Visual Studio's profiler to do this?

Also, in the mex function I created, I'm not using static arrays. The mex function is within a loop and is getting called thousands of times. I'm a C newbie, but I'm thinking that making some of these arrays static / persistent will speed things up, though I don't know how much. Does anyone have experience doing that? Do you think it may speed things up dramatically? Do you know of any links that would help explain how to modify my code to make arrays persistent?

Thanks!
From: Rune Allnor on
On 24 Jun, 17:03, "Brian " <k...(a)ee.washington.edu> wrote:
> I've rewritten a slow Matlab code loop in C and it's already about 30x faster. I'd like to profile the C code that I've written to see how I can make it faster. How can I use Visual Studio's profiler to do this?

If you want to use VS to profile your code, I'd skip MEX and
write a stand-alone C program I would then profile in VS.
Mind you - you will need a rather hefty version of VS to get
the profiler. In VS2008 you will need the $2500'ish enterprise
edition. If you are lucky, you might get away with the VS2010
pro edition.

> Also, in the mex function I created, I'm not using static arrays. The mex function is within a loop and is getting called thousands of times. I'm a C newbie, but I'm thinking that making some of these arrays static / persistent will speed things up, though I don't know how much. Does anyone have experience doing that? Do you think it may speed things up dramatically? Do you know of any links that would help explain how to modify my code to make arrays persistent?

The C keyword to look out for is 'static'. If you declare
the array as static in the source code, chances are that
it might not need to be de-/re-allocated between calls.

Don't have too high hopes about static arrays making a huge
difference, though. The overhead in the MEX gateway is very
large, which would likely dwarf the memory allocation issue.

Apart from that, keep in mind that you are playing with fire.
Sure, C *can* produce significantly faster programs, but unless
you know exactky what you are doing, you might end up in some
serious trouble.

Rune
From: Brian on
Hi Rune,

Thanks for the advice. Fortunately, my university has an agreement with Microsoft so students can get VS 2010 Ultimate free :-)

So you're recommending I write the entire program in C? I have a 1000+ line program in Matlab, but about 99% of the time is spent in a 50 line loop, so that's why I'd like to just write a mex function for that loop.

So is it not possible to profile mex functions written in C with VS?

Thanks!
From: Rune Allnor on
On 24 Jun, 17:48, "Brian " <k...(a)ee.washington.edu> wrote:
> Hi Rune,
>
> Thanks for the advice. Fortunately, my university has an agreement with Microsoft so students can get VS 2010 Ultimate free :-)
>
> So you're recommending I write the entire program in C? I have a 1000+ line program in Matlab, but about 99% of the time is spent in a 50 line loop, so that's why I'd like to just write a mex function for that loop.

I am saying that *I* would have written the C part in a way
that would be easy to profile.

> So is it not possible to profile mex functions written in C with VS?

VS is not set up to deal with MEX. VS is set up to deal with C.
If you want to take full advantage of the C tools VS offer,
you should write your programs in a way that let you do that.

Rune