Namespaces and the timeit module

2004-12-13 Thread Roy Smith
I'm playing with the timeit module, and can't figure out how to time a function call. I tried: def foo (): x = 4 return x t = timeit.Timer ("foo()") print t.timeit() and quickly figured out that the environment the timed code runs under is not what I expected: Traceback (most recent

Namespaces and the timeit module

2004-12-13 Thread Michele Simionato
I use a little wrapper to timeit: $ cat timeit_.py import timeit, __main__, warnings warnings.filterwarnings('ignore', 'import \* only allowed at module level',SyntaxWarning) def timeit(stmt, setup='from __main__ import *', n=1000): t = timeit.Timer(stmt,setup) try: print t.repeat(numb

Re: Namespaces and the timeit module

2004-12-14 Thread David M. Cooke
Roy Smith <[EMAIL PROTECTED]> writes: > I'm playing with the timeit module, and can't figure out how to time a > function call. I tried: > > def foo (): > x = 4 > return x > > t = timeit.Timer ("foo()") > print t.timeit() > > and quickly figured out that the environment the timed code ru

Re: Namespaces and the timeit module

2004-12-14 Thread Roy Smith
[EMAIL PROTECTED] (David M. Cooke) wrote: > > It seems kind of surprising that I can't time functions. Am I just not > > seeing something obvious? > > Like the documentation for Timer? :-) > > class Timer([stmt='pass' [, setup='pass' [, timer=]]]) > > You can't use statements defined elsewhe