Fastest way to count your iterations?

Andrew Dalke adalke at
Mon Jul 28 21:08:41 CEST 2003

Tracy Ruggles:
> If you're writing a simple script and you want to give an update of
> its progress...  Is this the fastest way to do it (assuming that what
> you're iterating through is very, very long and the time to process
> each item is relatively short)...

What you wrote is very standard, so I would suggest using it.

However, if you want performance, try variations on

def counter(items, f, sep=1000):
  next_item = iter(items).next
  values = range(sep)
  for i in range(0, sys.maxint, sep):
    for j in values:
    print i+sep+1

                    dalke at

More information about the Python-list mailing list