Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reducing the time for MATLAB code

Status
Not open for further replies.

brango

Mechanical
Feb 26, 2008
17
Hello, I am working on a code on MATLAB 7.0. It takes me about 5 hours for my program to run once.

I am working on optimization, so I have some functions that are called thousands of times.

I read about vectorizing the code, but im dealing with sophisticated loops and im not sure if they can be vectorized.

I also tried to run the profiler, and I analyzed the function taking most of the time.

For example, it says 35 secs for "other lines and overhead" and i was wondering if i can do something to reduce this time.

Other lines in my function dont take much time relative to the 35 secs mentioned above.

I can post the results obtained in the profiler if it helps.

Thank you for any help.

 
Replies continue below

Recommended for you

35 secs vs. 5 hrs

Is there a disconnect here?

TTFN

FAQ731-376
 
Hello,

Thanks for your reply.

35 secs for running the function once.

The code runs 200 times in order to perform optimization, and each time it runs the function itself gets called more than once. So 35 secs which initially seems a very small time becomes 35secs x 200 x no. of calls per 1 loop.

Thanks.
 
Optimization of existing code usually translates into at best 2x improvement? You need more like 100x improvement, which means completely rethinking your approach.

It sounds like you're running your own solver loop, which is usually going to be pathetic in performance compared to built-in functions.

TTFN

FAQ731-376
 
Hello.

Yes, the functions Im using arent built-in. What I wanted to know is whether the time taken for "other lines and overhead" can be reduced or no. I dont even know what overhead is. It is taking %87 of the function time.

Thanks.
 
Yes, but you're only going to get a factor of 2 or so in performance improvement, because you are limited to using function calls, while the built-in solver functions use native code.

One possibility is to compile the code; that might make it somewhat faster.

TTFN

FAQ731-376
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor