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

Add variable access benchmark to Tools/Scripts #80065

Closed
rhettinger opened this issue Feb 1, 2019 · 5 comments
Closed

Add variable access benchmark to Tools/Scripts #80065

rhettinger opened this issue Feb 1, 2019 · 5 comments
Labels
3.8 only security fixes performance Performance or resource usage

Comments

@rhettinger
Copy link
Contributor

BPO 35884
Nosy @rhettinger, @miss-islington
PRs
  • bpo-35884: Add variable access benchmarking script #11725
  • bpo-35884: Add variable access benchmarking script #11725
  • bpo-35884: Add missing FIFO queue benchmark #11898
  • bpo-35884: Add string-keys-only microbenchmark for dict access to var_access_benchmark.py #11905
  • 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 2019-02-03.06:55:59.157>
    created_at = <Date 2019-02-01.20:19:39.894>
    labels = ['3.8', 'performance']
    title = 'Add variable access benchmark to Tools/Scripts'
    updated_at = <Date 2019-03-25.08:21:01.704>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2019-03-25.08:21:01.704>
    actor = 'rhettinger'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-02-03.06:55:59.157>
    closer = 'rhettinger'
    components = ['Demos and Tools']
    creation = <Date 2019-02-01.20:19:39.894>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35884
    keywords = ['patch', 'patch']
    message_count = 5.0
    messages = ['334716', '334719', '334788', '335718', '338790']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'miss-islington']
    pr_nums = ['11725', '11725', '11898', '11905']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue35884'
    versions = ['Python 3.8']

    @rhettinger
    Copy link
    Contributor Author

    Adding a short script that I've found useful many times over the past decade. It has allowed my to quickly notice performance regressions and has helped identify places in need of optimization work. It is also useful for building a empirical mental model of the relative cost of various kinds of variable access -- this is useful in writing high performance code.

    @rhettinger rhettinger added 3.8 only security fixes performance Performance or resource usage labels Feb 1, 2019
    @rhettinger
    Copy link
    Contributor Author

    Here's what the output looks like (here am comparing a fresh Py3.8 with Clang versus the same build with GCC-8):

    $ make distclean && ./configure && make
    $ py Tools/scripts/var_access_benchmark.py
    Speed of different kinds of variable accesses:
       4.2 μs	read_local
       4.7 μs	read_nonlocal
      13.7 μs	read_global
      18.5 μs	read_builtin
      18.2 μs	read_classvar
      26.8 μs	read_instancevar
      20.3 μs	read_instancevar_slots
      19.1 μs	read_namedtuple
      26.9 μs	read_boundmethod
       4.5 μs	write_local
       4.8 μs	write_nonlocal
      18.8 μs	write_global
      89.9 μs	write_classvar
      37.1 μs	write_instancevar
      25.7 μs	write_instancevar_slots
       0.3 μs	loop_overhead
    
    $ make distclean && ./configure CC=gcc-8 && make
    $ py Tools/scripts/var_access_benchmark.py
    Speed of different kinds of variable accesses:
       4.0 μs	read_local
       4.2 μs	read_nonlocal
      11.4 μs	read_global
      16.3 μs	read_builtin
      16.4 μs	read_classvar
      24.8 μs	read_instancevar
      20.1 μs	read_instancevar_slots
      16.8 μs	read_namedtuple
      23.2 μs	read_boundmethod
       4.3 μs	write_local
       4.5 μs	write_nonlocal
      15.4 μs	write_global
      89.4 μs	write_classvar
      33.5 μs	write_instancevar
      24.5 μs	write_instancevar_slots
       0.3 μs	loop_overhead

    @rhettinger
    Copy link
    Contributor Author

    New changeset f75d59e by Raymond Hettinger in branch 'master':
    bpo-35884: Add variable access benchmarking script (GH-11725)
    f75d59e

    @miss-islington
    Copy link
    Contributor

    New changeset 43766f8 by Miss Islington (bot) (Raymond Hettinger) in branch 'master':
    bpo-35884: Add missing FIFO queue benchmark (GH-11898)
    43766f8

    @rhettinger
    Copy link
    Contributor Author

    New changeset 68d228f by Raymond Hettinger (Stefan Behnel) in branch 'master':
    bpo-35884: Add string-keys-only microbenchmark for dict access to var_access_benchmark.py (GH-11905)
    68d228f

    @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.8 only security fixes performance Performance or resource usage
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants