Namespaces and the timeit module

Discussion in 'Python' started by Michele Simionato, Dec 14, 2004.

  1. 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(number=n)
    except: t.print_exc()

    You can import it with "from timeit_ import timeit" and it gives you access to
    your __main__ program namespace.


    Michele Simionato
     
    Michele Simionato, Dec 14, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Christensen
    Replies:
    4
    Views:
    605
    Peter Otten
    Jul 14, 2004
  2. fortepianissimo

    module timeit and variable scope

    fortepianissimo, Aug 2, 2004, in forum: Python
    Replies:
    0
    Views:
    281
    fortepianissimo
    Aug 2, 2004
  3. Roy Smith

    Namespaces and the timeit module

    Roy Smith, Dec 14, 2004, in forum: Python
    Replies:
    2
    Views:
    462
    Roy Smith
    Dec 14, 2004
  4. Replies:
    2
    Views:
    280
  5. ChaosKCW
    Replies:
    5
    Views:
    306
    bruno at modulix
    Nov 11, 2005
Loading...

Share This Page