-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Comments
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. |
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 |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: