This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fix for timeit when the statement is a string and the setup is not (and tests)
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: georg.brandl, michael.henry, python-dev, r.david.murray, rhettinger, serhiy.storchaka, tdriscol
Priority: normal Keywords: patch

Created on 2009-03-31 21:01 by tdriscol, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
timeit_issue_5633.patch michael.henry, 2011-03-16 22:19 Adds unit tests and an alternative fix for this bug review
timeit_callable_setup.patch serhiy.storchaka, 2015-05-13 13:45 review
timeit_callable_setup_refactor.patch serhiy.storchaka, 2015-05-13 14:36 review
Messages (7)
msg84902 - (view) Author: Tim Driscoll (tdriscol) Date: 2009-03-31 21:01
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.
msg84910 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2009-03-31 21:17
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.
msg84933 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-03-31 22:07
I'll look at it.
msg131184 - (view) Author: Michael Henry (michael.henry) * Date: 2011-03-16 22:19
Issue #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.
msg243086 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-13 13:44
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.
msg243094 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-13 14:36
Here is more complicated patch, that not only fixes handling of callable setup, but also simplifies the implementation of timeit constructor.
msg244471 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-05-30 16:46
New changeset 14d1018940cb by Serhiy Storchaka in branch '2.7':
Issue #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 #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 #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 #5633: Fixed timeit when the statement is a string and the setup is not.
https://hg.python.org/cpython/rev/fd01cbe4336e
History
Date User Action Args
2022-04-11 14:56:47adminsetgithub: 49883
2015-05-30 16:55:14serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-05-30 16:46:06python-devsetnosy: + python-dev
messages: + msg244471
2015-05-30 16:18:52serhiy.storchakasetassignee: serhiy.storchaka
versions: + Python 3.6
2015-05-13 14:36:36serhiy.storchakasetfiles: + timeit_callable_setup_refactor.patch

messages: + msg243094
2015-05-13 13:45:03serhiy.storchakasetfiles: + timeit_callable_setup.patch
2015-05-13 13:44:48serhiy.storchakasetversions: + Python 2.7, Python 3.4, Python 3.5, - Python 3.1, Python 3.2, Python 3.3
nosy: + serhiy.storchaka

messages: + msg243086

stage: patch review
2013-03-28 10:03:03georg.brandlsetassignee: georg.brandl -> (no value)
2012-06-25 17:56:54tshepangsettitle: 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)
2011-03-16 22:19:47michael.henrysetfiles: + timeit_issue_5633.patch
versions: + Python 3.2, Python 3.3
nosy: + r.david.murray, michael.henry

messages: + msg131184

keywords: + patch
2009-03-31 22:07:46georg.brandlsetmessages: + msg84933
2009-03-31 21:17:26rhettingersetassignee: rhettinger -> georg.brandl

messages: + msg84910
nosy: + georg.brandl
2009-03-31 21:10:43tdriscolsettitle: 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)
2009-03-31 21:04:50rhettingersetassignee: rhettinger

nosy: + rhettinger
2009-03-31 21:01:38tdriscolcreate