Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let timeit accept functions #43768

Closed
edemaine mannequin opened this issue Aug 3, 2006 · 3 comments
Closed

Let timeit accept functions #43768

edemaine mannequin opened this issue Aug 3, 2006 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@edemaine
Copy link
Mannequin

edemaine mannequin commented Aug 3, 2006

BPO 1533909
Nosy @birkenfeld
Files
  • patch: Patch implementing proposed changes to timeit
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2007-03-13.19:32:46.000>
    created_at = <Date 2006-08-03.14:32:38.000>
    labels = ['library']
    title = 'Let timeit accept functions'
    updated_at = <Date 2007-03-13.19:32:46.000>
    user = 'https://bugs.python.org/edemaine'

    bugs.python.org fields:

    activity = <Date 2007-03-13.19:32:46.000>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2006-08-03.14:32:38.000>
    creator = 'edemaine'
    dependencies = []
    files = ['7445']
    hgrepos = []
    issue_num = 1533909
    keywords = ['patch']
    message_count = 3.0
    messages = ['50816', '50817', '50818']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'edemaine']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1533909'
    versions = ['Python 2.6']

    @edemaine
    Copy link
    Mannequin Author

    edemaine mannequin commented Aug 3, 2006

    I see that there is a history of proposed (and
    rejected) patches to allow timeit to see various module
    global namespaces, etc. But I'm surprised that no one
    has proposed the obvious functional solution: allow the
    arguments (particularly 'stmt') to be functions that
    get called, instead of strings that get parsed and
    executed. This does increase the measurement overhead
    slightly, adding in the function call, but in many
    cases it is far more useful within scripts. To time
    some part of the code, you can replace a function call
    'foo()' with 'timeit.Timer(foo).timeit()'.

    I also propose helper functions for use within scripts:
    timeit.timeit(...) is shorthand for
    timeit.Timer(...).timeit(...), and timeit.repeat(...)
    is shorthand for timeit.Timer(...).repeat(...). Now
    you can replace a function call 'foo()' with
    'timeit.timeit(foo)', e.g., 'print "foo takes",
    timeit.timeit(foo), "seconds"'.

    Attached is a simple patch implementing both of these
    changes. Documentation would need updating too.

    @edemaine edemaine mannequin closed this as completed Aug 3, 2006
    @edemaine edemaine mannequin added the stdlib Python modules in the Lib dir label Aug 3, 2006
    @edemaine edemaine mannequin closed this as completed Aug 3, 2006
    @edemaine edemaine mannequin added the stdlib Python modules in the Lib dir label Aug 3, 2006
    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=849994

    Please use four-space indents when contributing library
    code. Perhaps unicode "stmt" arguments should also be
    allowed. Perhaps other arguments should be checked with
    callable() to exclude lists or something like that.

    @birkenfeld
    Copy link
    Member

    Reformatted the patch, bugfixed it, added documentation and committed as rev. 54348.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant