Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Slowing process when running a program with multiple nested loops

From   David Kantor <>
Subject   Re: st: Slowing process when running a program with multiple nested loops
Date   Mon, 14 Jan 2013 12:52:39 -0500

At 11:44 AM 1/14/2013, Ly Tran wrote:
I wrote a program, in which there are multiple nested loops (because
there are 7 parameters, each could receive one of 5-7 different
The program runs really fast at first, but starts slowing down when
getting to around the 300th iteration. By 500th iteration, it slows
down significantly, and I could never wait until the whole thing ends
(the longest I have waited was 2 hours).

Does anybody know what could be the cause of this slowing down? "Set
memory" doesn't seem to help.

Any idea will be much appreciated.
thank you.

I think that most of would agree that we would need to see your code to be able to say what the problem is. Meanwhile, did you mean that the loops are nested to a depth of 7? That's unusually deep.

Just generally speaking, with loops, there are often actions that are placed inside that don't need to be there; they can be moved "up" or "out" (sometimes requiring a bit of modification) so as to not be done multiple times unnecessarily. From what you describe, it seems that the work done in each iteration is accumulating; each iteration does a bit more work than the previous. There may be some unnecessary repetition as described above. But it also seems that there is something that grows and gets dragged along with each iteration -- again possibly unnecessarily. This is analogous to a cumulative song, such as "The Twelve Days of Christmas"; the 12th verse is much longer than the first.

On the other hand, does the true complexity of the task grow with each iteration? Do you expect the 300th iteration to naturally be more complex to perform than the first?

Show us your code if you want more help.


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index