Message403083
> Do you have any explanation of this?
I think its because current PyFunction_New tries to get docstring always.
See this pull request (lazy-func-doc). https://github.com/python/cpython/pull/28704
lazy-func-doc is faster than co-docstring and remove-docstring in both of with/without docstring.
```
# co-docstring vs lazy-func-doc.
$ load-none-co-docstring/release/bin/pyperf timeit --compare-to ./cpython/release/bin/python3 --python-names lazy-func-doc:co-docstring --duplicate=100 "def f(): pass"
lazy-func-doc: ..................... 58.6 ns +- 1.6 ns
co-docstring: ..................... 60.3 ns +- 2.0 ns
Mean +- std dev: [lazy-func-doc] 58.6 ns +- 1.6 ns -> [co-docstring] 60.3 ns +- 2.0 ns: 1.03x slower
$ load-none-co-docstring/release/bin/pyperf timeit --compare-to ./cpython/release/bin/python3 --python-names lazy-func-doc:co-docstring --duplicate=100 "def f(): 'doc'"
lazy-func-doc: ..................... 59.6 ns +- 1.1 ns
co-docstring: ..................... 62.3 ns +- 1.7 ns
Mean +- std dev: [lazy-func-doc] 59.6 ns +- 1.1 ns -> [co-docstring] 62.3 ns +- 1.7 ns: 1.05x slower
# remove docstring vs lazy-func-doc
$ load-none-remove-docstring/release/bin/pyperf timeit --compare-to ./cpython/release/bin/python3 --python-names lazy-func-doc:remove-docstring --duplicate=100 "def f(): pass"
lazy-func-doc: ..................... 58.0 ns +- 1.1 ns
remove-docstring: ..................... 60.5 ns +- 1.5 ns
Mean +- std dev: [lazy-func-doc] 58.0 ns +- 1.1 ns -> [remove-docstring] 60.5 ns +- 1.5 ns: 1.04x slower
$ load-none-remove-docstring/release/bin/pyperf timeit --compare-to ./cpython/release/bin/python3 --python-names lazy-func-doc:remove-docstring --duplicate=100 "def f(): 'doc'"
lazy-func-doc: ..................... 59.9 ns +- 2.3 ns
remove-docstring: ..................... 63.5 ns +- 1.5 ns
Mean +- std dev: [lazy-func-doc] 59.9 ns +- 2.3 ns -> [remove-docstring] 63.5 ns +- 1.5 ns: 1.06x slower
```
Note that this benchmark runs on my MacBook. Results may be bit unstable, although I don't touch anything (especially, browser) during the run. |
|
Date |
User |
Action |
Args |
2021-10-03 11:22:46 | methane | set | recipients:
+ methane, gvanrossum, rhettinger, terry.reedy, Mark.Shannon, serhiy.storchaka, Guido.van.Rossum, iritkatriel |
2021-10-03 11:22:46 | methane | set | messageid: <1633260166.76.0.627249186176.issue36521@roundup.psfhosted.org> |
2021-10-03 11:22:46 | methane | link | issue36521 messages |
2021-10-03 11:22:46 | methane | create | |
|