Re: Trivial non-local-returns efficiency question

Guido.van.Rossum@cwi.nl
Sat, 24 Sep 1994 00:31:17 +0200

I lean towards try/finally too, reasoning that making language
constructs work for you is usually faster than simulating anything
using variables -- the cost of checking and assigning to a variable
can be considerable. On the other hand, I've been surprised too, so I
guess that profiling (especially using jar's new profile module) is
the only way to find the definitive truth.

Another possible way of structuring this, using neither try/finally
nor boolean variables, would be:

while 1:
got.append(rec)
rec = self.db.search(metalbase.NEXT, rec)
if rec: # Validate new rec:
for key, val in pairs:
if getattr(rec, key) != val:
# Done once we're past ordered index recs:
break
else:
# !!! get here if no break in the for loop
continue
# !!! get here only via in break in the for loop
break

if idx != wasIdx:
self.currindex(wasIdx)
return MbSubDict(self, got) # ===v

Again, I don't know offhand if this is any faster..

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>