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

Home » Public Forums » archive » Re: How to speed up large FOR loops?
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: How to speed up large FOR loops? [message #79807 is a reply to message #79804] Tue, 10 April 2012 11:21 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Tuesday, April 10, 2012 12:26:27 PM UTC-4, Saurav Dhital wrote:
> Yes. More specifically, I reform arrays and assign them to the new
> FITS structure. This happens a lot.

This is a problem. A pattern like this,
L = [0]
for i = 0, 1000000-1 do L = [L, i]

will run quickly at first and then slow down as L gets longer and longer.

The trick is to pre-allocate your lists like L. If the size of L is not known in advance, then pre-allocate a reasonable fixed size to begin with, and then grow it by factors of 2 as needed (up to a point).

At the end, you will need to trim the unused portion of L.

I do this kind of pattern all the time, and it can be quite efficient.

Craig
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Creating netCDF file
Next Topic: How to speed up large FOR loops?

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

Current Time: Wed Oct 08 15:28:03 PDT 2025

Total time taken to generate the page: 0.00452 seconds