comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: For loops vs. matrix operations
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: For loops vs. matrix operations [message #37440 is a reply to message #37439] Wed, 17 December 2003 15:05 Go to previous message
mperrin+news is currently offline  mperrin+news
Messages: 81
Registered: May 2001
Member
Jonathan Greenberg <greenberg@ucdavis.edu> wrote:
> I know some matrix programs perform better if you do straigh matrix math vs.
> a for-next loop -- is idl this way? E.g. is:
>
> array=intarr(10000)
> for i=0,(10000-1) do begin
> array[i]=array[i]+1
> endfor
>
> MUCH slower than:
>
> array=intarr(10000)
> array=array+1
>
> ?

Yes, the for loop version will be *vastly* slower. This is because IDL
makes a seperate trip through the parse/interpret cycle for every pass
through the for loop, greatly increasing the overhead.

> I'm trying to figure out how much time I should be using rewriting some code
> to optimize the algorithm, which is why I'm asking (the code is more complex
> than above, obviously, but I did notice I could "matricize" some of the code
> in places)...

Matricize as much as you possibly can!

- Marshall
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: always widget!
Next Topic: Re: How to make IDL be quiet

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:57:24 PDT 2025

Total time taken to generate the page: 0.00282 seconds