classification
Title: micro-optimizations in functools.reduce()
Type: performance Stage: patch review
Components: Extension Modules Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: sir-sigurd, xtreak
Priority: normal Keywords: patch

Created on 2018-08-01 05:09 by sir-sigurd, last changed 2018-08-01 09:12 by inada.naoki.

Pull Requests
URL Status Linked Edit
PR 8598 open sir-sigurd, 2018-08-01 05:10
Messages (1)
msg322841 - (view) Author: Sergey Fedoseev (sir-sigurd) * Date: 2018-08-01 05:09
`PyTuple_SetItem()` can be replaced with macro version and `PyObject_Call()` can be used instead of `PyEval_CallObject()`.

Here's benchmark results:

$ python -m perf timeit --compare-to ~/tmp/cpython-master-venv/bin/python -s "from functools import reduce; from operator import is_; r = range(50000)" "reduce(is_, r)"
/home/sergey/tmp/cpython-master-venv/bin/python: ..................... 1.64 ms +- 0.01 ms
/home/sergey/tmp/cpython-venv/bin/python: ..................... 1.40 ms +- 0.00 ms

Mean +- std dev: [/home/sergey/tmp/cpython-master-venv/bin/python] 1.64 ms +- 0.01 ms -> [/home/sergey/tmp/cpython-venv/bin/python] 1.40 ms +- 0.00 ms: 1.17x faster (-15%)
History
Date User Action Args
2018-08-01 09:12:25inada.naokisettype: enhancement -> performance
versions: + Python 3.8
2018-08-01 08:27:28xtreaksetnosy: + xtreak
2018-08-01 05:10:27sir-sigurdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8107
2018-08-01 05:09:03sir-sigurdcreate