A Loop Which Iterations Take Increasing Amount of Time
Posted: Sun Aug 17, 2014 2:42 pm
Is there any reason why this loop's iterations,
would require increasing amounts of time when there is no reason for that in the code? Perhaps due to some memory quirk?
Iteration 100 is a several orders of magnitude slower than the 1st iteration. The statements between iterations are completely independent.
If I run exactly the same code as follows, then the program runs fast at each iteration:
where the Eviews program <program> does exactly the same as [do something] above.
My results are exactly the same between the programs. The [do something] part consists of a large number of other loops with vector and matrix aggregation operations, and freezing model output for saving some of its cells. Run time should be around 10 minutes, but takes 4 hours with the former code organisation.
I can make a minimum working example if someone does not have an obvious (i.e. programmatic or technical) reason why this might occur.
Code: Select all
for !i=1 to 100
[do something]
next
Iteration 100 is a several orders of magnitude slower than the 1st iteration. The statements between iterations are completely independent.
If I run exactly the same code as follows, then the program runs fast at each iteration:
Code: Select all
for !i=1 to 100
exec <program>
next
My results are exactly the same between the programs. The [do something] part consists of a large number of other loops with vector and matrix aggregation operations, and freezing model output for saving some of its cells. Run time should be around 10 minutes, but takes 4 hours with the former code organisation.
I can make a minimum working example if someone does not have an obvious (i.e. programmatic or technical) reason why this might occur.