Re: many "ifs" versus linked list of true cases



Mark Morss wrote:
I want to solve a large set, say 5000, of numbered, quite similar
problems but with different values of certain arguments in each case.
Solution of each case is by iteration; the number of iterations
required for a given case could be large or small, depending on the
values of parameters. The maximum number of necessary iterations is
perhaps 50, but only a small proportion of cases are likely to require
very many iterations.

For particular reasons I want my outer loop to be iteration number; so
that on a given iteration, I may or may not need to process a given
case, according to whether or not it has been solved.

My question is, which is more efficient: on each iteration, to ask in
each of 5000 cases whether say "solved(case) == .TRUE.", or to
maintain a linked list integer indices of so-far-unsolved cases and
cycle over that list each time, deleting cases from the list as they
are solved?

I have a suspicion that "it depends," but if anyone has a sense that
one method is likely to be better, I'd like to know about it. There
was some suggestion in earlier discussions here that allocations
aren't all that cheap, so is the seeming elegance of not always asking
"is this case solved?" is outweighed by the expense of that?


The general rule for determining which method is faster is to try it both ways. If speed really is important the time spent coding will be insignificant. If speed isn't really important why worry about which method to use?
.