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

timeit: use powers of 2 in autorange(), instead of powers of 10 #72655

Closed
vstinner opened this issue Oct 18, 2016 · 8 comments
Closed

timeit: use powers of 2 in autorange(), instead of powers of 10 #72655

vstinner opened this issue Oct 18, 2016 · 8 comments
Labels
3.7 (EOL) end of life performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

BPO 28469
Nosy @vstinner, @serhiy-storchaka
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • timeit_autorange_pow2.patch
  • timeit_autorange_numbers.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 = None
    closed_at = <Date 2016-10-23.12:19:09.850>
    created_at = <Date 2016-10-18.16:13:11.315>
    labels = ['3.7', 'library', 'performance']
    title = 'timeit: use powers of 2 in autorange(), instead of powers of 10'
    updated_at = <Date 2017-03-31.16:36:15.077>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:15.077>
    actor = 'dstufft'
    assignee = 'none'
    closed = True
    closed_date = <Date 2016-10-23.12:19:09.850>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-10-18.16:13:11.315>
    creator = 'vstinner'
    dependencies = []
    files = ['45134', '45186']
    hgrepos = []
    issue_num = 28469
    keywords = ['patch']
    message_count = 8.0
    messages = ['278899', '278905', '278906', '278915', '278916', '279187', '279245', '279254']
    nosy_count = 3.0
    nosy_names = ['vstinner', 'python-dev', 'serhiy.storchaka']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue28469'
    versions = ['Python 3.7']

    @vstinner
    Copy link
    Member Author

    In the issue bpo-28240, I changed the default repeat from 3 to 5 in timeit. Serhiy wrote (msg277157): "For now default timeit run takes from 0.8 to 8 sec. Adding yet 5 sec makes a user more angry."

    I propose to use powers to 2, instead of powers of 10, in timeit autorange to reduce the total duration of the microbenchmark.

    • Without the patch, the worst case: 4.0 * 6 = 24 seconds.

    • With the patch, the worst case is: 0.4 * 6 = 2.4 seconds

    • 6: autorange (1 iteration) + 5 repeatition

    • autorange uses a minimum of 200 ms, so the worst case is 200 ms * 10 before, or 200 ms * 2 after

    @vstinner vstinner added 3.7 (EOL) end of life performance Performance or resource usage labels Oct 18, 2016
    @serhiy-storchaka
    Copy link
    Member

    "131072 loops" in a report looks not human friendly. I would prefer using a sequence of round numbers: 1, 2, 5, 10, 20, 50, 100, ...

    @vstinner
    Copy link
    Member Author

    "131072 loops" in a report looks not human friendly.

    In my perf module, I use 2^n syntax for numbers larger than 1024. Syntax accepted in command line arguments.

    @serhiy-storchaka
    Copy link
    Member

    The perf module doesn't report the number of loops by default.

    @vstinner
    Copy link
    Member Author

    The perf module doesn't report the number of loops by default.

    Right, it's hidden by default. I consider that it's not an useful information for end users.

    If you want more details (see the number of inner and outer loops), use --verbose ("python3 -m perf timeit -v ...") or the stats commands ("python3 -m perf stats file.json").

    @serhiy-storchaka
    Copy link
    Member

    Following patch takes numbers from the sequence 1, 2, 5, 10, 20, 50, ... It also updates the documentation and tests.

    @serhiy-storchaka serhiy-storchaka added the stdlib Python modules in the Lib dir label Oct 22, 2016
    @vstinner
    Copy link
    Member Author

    timeit_autorange_numbers.patch: LGTM.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 23, 2016

    New changeset 8e6cc952adc6 by Serhiy Storchaka in branch 'default':
    Issue bpo-28469: timeit now uses the sequence 1, 2, 5, 10, 20, 50,... instead
    https://hg.python.org/cpython/rev/8e6cc952adc6

    @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
    3.7 (EOL) end of life performance Performance or resource usage stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants