Fastest way to count your iterations?
tracer at axiomfire.com
Mon Jul 28 20:41:42 CEST 2003
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)...
def counter(items, f, sep=1000):
i = 0
for item in items:
i += 1
if i % sep == 0:
[ is the modulus operator the quickest way to find out if you're
really at the 1000th item? ]
More information about the Python-list