Disregard ... Operator Error


I am currently going over the subject of measuring timing processing times.

A new module that I have been introduced to is the timer module. I noticed that by
importing it, it automatically prints the following onto the IDLE shell interpreter. Is this a
bug. I noticed that the book did not show this as being printed for an example incorporating
the module.

You can try the following (this should suffice) into a module and run it:

import timer

What is printed onto the shell interpreter is:

t =  0.0018258999989484437
d =  (0.00020050000603077933, 'SPAM')
b =  (9.999348549172282e-08, 'SPAM')
c =  0.003384900002856739

This would be a bit annoying if this would print out every time that you would import the module.

I’m not seeing that.

Print out timer.__file__ to see where that file is located. Is it in the Python folder?

For measuring processing times, the recommended module is timeit.

instead of

import timer


from timer import timer

and see if it helps

Hello all,

thank you for responding to my query.

This is the test script in its totality:

# File timeseqs.py
"Test the relative speed of iteration tool alternatives."

import sys, timer # Import timer functions

reps = 10000
repslist = list(range(reps)) # Hoist out, list in both 2.X/3.X

def forLoop():
    res = []
    for x in repslist:
    return res
def listComp():
    return [abs(x) for x in repslist]

def mapCall():
    return list(map(abs, repslist)) # Use list() here in 3.X only!

 # return map(abs, repslist)
def genExpr():
    return list(abs(x) for x in repslist) # list() required to force results

def genFunc():
    def gen():
        for x in repslist:
            yield abs(x)
    return list(gen()) # list() required to force results

print('\nSystem version:',sys.version)
for test in (forLoop, listComp, mapCall, genExpr, genFunc):
    (bestof, (total, result)) = timer.bestoftotal(5, 1000, test)
    print ('%-9s: %.5f => [%s...%s]' % (test.__name__, bestof, result[0], result[-1]))

I believe that printout is due to the timer module.


My mistake.

This was a file from a previous example that I had worked on named timer.py.
Thus, it is not a Python module. Since I am following the book, it is from an
earlier file that we had worked on and of which I had added my own code for
testing purposes at the time. Namely, printing out those values.

My mistake.

My apologies. :open_mouth::flushed: