Inada Naoki <songofaca...@gmail.com> added the comment:

> 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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36521>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to