0

I'm looking for a way to do very simple profiling in a mex program triggered from matlab. I compile from matlab using: mex -O CFLAGS="\$CFLAGS -std=c99" rrt.c and then run my program. Really all I need is a thing to see, which of two functions runs faster. However since it all goes down in about 1/100s time(NULL) is not fast enough.

Is there a simple function in C I could call, or are there any real profiling methods for a mex program in matlab?

I saw this post beeing treated as duplicate, but what I want to know is a way to profile the C code compiled with gcc in matlab, or easier some timing functions. I use OSX 10.7.5 and matlab 2014b. Thanks for any hints.

Edit: Actually chappjc's hint got me looking for clock(), which does, what I need for the time beeing. An actual profiling would still be nice though.

The reason not to use tic/toc or similar is, that I have a base and a modified code, which both run with random samples. Compiling 2 versions of basically the same code each time I change something and having the extra step of exporting/importing the seed for the random number generator seems like a big hustle for exactly no value to me. I write code such that I don't have to repeat myselft. Having two seperate functions would need quite some duplicate code, since the changes are easy and a few, but deeply integrated in not just one spot.

Community
  • 1
  • 1
mike
  • 791
  • 11
  • 26
  • What you want _is_ a C profiler. Or basic timing functions in C like [`clock`](http://www.cplusplus.com/reference/ctime/clock/). Or maybe tic/toc in MATLAB. – chappjc Apr 25 '15 at 16:22
  • tic/toc doesn't work, since both functions have to be in one C program, which is at once executed by matlab. I corrected my statement. And will take a look at clock, thanks for the hint. – mike Apr 25 '15 at 17:07
  • Are you timing a sub-function inside your mex code or how long the whole mex function takes to execute within Matlab? Please indicate why you think the timing needs to be performed in the C code itself? If you want to compare two functions, just compile two versions of your code and time each. – horchler Apr 25 '15 at 17:09
  • Call the function 100 times in a for-loop and measure the total time. – siliconwafer Apr 29 '15 at 19:38

0 Answers0