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

fix for timeit when the statement is a string and the setup is not (and tests) #49883

Closed
tdriscol mannequin opened this issue Mar 31, 2009 · 7 comments
Closed

fix for timeit when the statement is a string and the setup is not (and tests) #49883

tdriscol mannequin opened this issue Mar 31, 2009 · 7 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tdriscol
Copy link
Mannequin

tdriscol mannequin commented Mar 31, 2009

BPO 5633
Nosy @birkenfeld, @rhettinger, @bitdancer, @serhiy-storchaka
Files
  • timeit_issue_5633.patch: Adds unit tests and an alternative fix for this bug
  • timeit_callable_setup.patch
  • timeit_callable_setup_refactor.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-05-30.16:55:14.404>
    created_at = <Date 2009-03-31.21:01:37.998>
    labels = ['type-bug', 'library']
    title = 'fix for timeit when the statement is a string and the setup is not (and tests)'
    updated_at = <Date 2015-05-30.16:55:14.403>
    user = 'https://bugs.python.org/tdriscol'

    bugs.python.org fields:

    activity = <Date 2015-05-30.16:55:14.403>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-05-30.16:55:14.404>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2009-03-31.21:01:37.998>
    creator = 'tdriscol'
    dependencies = []
    files = ['21253', '39358', '39360']
    hgrepos = []
    issue_num = 5633
    keywords = ['patch']
    message_count = 7.0
    messages = ['84902', '84910', '84933', '131184', '243086', '243094', '244471']
    nosy_count = 7.0
    nosy_names = ['georg.brandl', 'rhettinger', 'r.david.murray', 'tdriscol', 'python-dev', 'michael.henry', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5633'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @tdriscol
    Copy link
    Mannequin Author

    tdriscol mannequin commented Mar 31, 2009

    The patch and test is here:
    http://codereview.appspot.com/28161/show

    There were no tests so i added a few of them. The one that breaks
    without the patch to timeit is:
    test_setup_is_called_when_the_statment_is_string_and_the_setup_is_not()
    (sorry for the long name)

    Even if the patch is no good perhaps the test could be useful.

    @tdriscol tdriscol mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 31, 2009
    @rhettinger rhettinger self-assigned this Mar 31, 2009
    @tdriscol tdriscol mannequin changed the title timeit breaks when the statment is a string and the setup is not fix for timeit when the statment is a string and the setup is not (and tests) Mar 31, 2009
    @rhettinger
    Copy link
    Contributor

    Georg, this was your patch: http://bugs.python.org/issue1533909

    I don't think it should have been accepted so readily. It is not
    harmonious with all of the other proposals for improving timeit.

    No that it is out in the wild, I think all you can do is fix-up the docs.

    Also, the inner template function should have a func=func argument so
    that the func() call is localized. This affects the timings. Part of
    the concept of the module is to make the surrounding timing apparatus be
    as light-weight as possible so that the timings reflect the thing being
    timed without being obscured by the overhead of the timing module itself.

    @rhettinger rhettinger assigned birkenfeld and unassigned rhettinger Mar 31, 2009
    @birkenfeld
    Copy link
    Member

    I'll look at it.

    @michaelhenry
    Copy link
    Mannequin

    michaelhenry mannequin commented Mar 16, 2011

    Issue bpo-11578 added unit tests for timeit.py. Because of this bug, two tests
    were omitted. In the attached patch are the previously withheld unit tests
    and an alternate method of fixing the bug (developed before Tim's fix was
    noticed). It's not clear to me what timing-related issues influence the
    strategy for fixing this bug.

    @tshepang tshepang mannequin changed the title fix for timeit when the statment is a string and the setup is not (and tests) fix for timeit when the statement is a string and the setup is not (and tests) Jun 25, 2012
    @birkenfeld birkenfeld removed their assignment Mar 28, 2013
    @serhiy-storchaka
    Copy link
    Member

    Definitely there is a bug. The code of timeit is written to support string stmt and callable setup. Expected that locals available when the function is created, would be available when the function is executed. But this doesn't work. May be it worked in the earlier Python, I don't know. Due to the lack of tests this was unnoticed.

    Here is simpler patch that fixes the support of callable setup with string stmt.

    But I like Tim's approach (compile testing function using the single template), it makes the implementation simpler. I'll try to adapt it for current sources.

    @serhiy-storchaka
    Copy link
    Member

    Here is more complicated patch, that not only fixes handling of callable setup, but also simplifies the implementation of timeit constructor.

    @serhiy-storchaka serhiy-storchaka self-assigned this May 30, 2015
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 30, 2015

    New changeset 14d1018940cb by Serhiy Storchaka in branch '2.7':
    Issue bpo-5633: Fixed timeit when the statement is a string and the setup is not.
    https://hg.python.org/cpython/rev/14d1018940cb

    New changeset 89de73c0d848 by Serhiy Storchaka in branch '3.4':
    Issue bpo-5633: Fixed timeit when the statement is a string and the setup is not.
    https://hg.python.org/cpython/rev/89de73c0d848

    New changeset faea7c8bcb13 by Serhiy Storchaka in branch '3.5':
    Issue bpo-5633: Fixed timeit when the statement is a string and the setup is not.
    https://hg.python.org/cpython/rev/faea7c8bcb13

    New changeset fd01cbe4336e by Serhiy Storchaka in branch 'default':
    Issue bpo-5633: Fixed timeit when the statement is a string and the setup is not.
    https://hg.python.org/cpython/rev/fd01cbe4336e

    @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 type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants