timeit

D

Duncan Smith

This is possibly a stupid question, but I need to get this working quickly,
and I guess I'm just too tired / pressured to see what I'm doing wrong.
Clearly (from the output below) I can't pass the statement to an instance of
timeit.Timer, but I can execute it using exec(). Any idea what I need to do
to get this timed (using timeit). Cheers.
p = subtract.p_risk(t.values, 10)
"""
Traceback (most recent call last):
File "<pyshell#119>", line 1, in -toplevel-
tim.timeit(10)
File "C:\Python23\lib\timeit.py", line 158, in timeit
return self.inner(it, self.timer)
File "<timeit-src>", line 6, in inner
NameError: global name 'subtract' is not defined

# yet0.242621453769059
 
S

Skip Montanaro

Duncan> This is possibly a stupid question, but I need to get this
Duncan> working quickly, and I guess I'm just too tired / pressured to
Duncan> see what I'm doing wrong.

Import the subtract module in a setup arg to your Timer() constructor:

tim = timeit.Timer(setup-'import subtract', stmt=s)

Skip
 
S

Skip Montanaro

Skip> tim = timeit.Timer(setup-'import subtract', stmt=s)

Whoops! '-' should of course be '='...

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top