Message289100
The pull request makes functools.partial() faster for positional arguments. It avoids the creation of a tuple for positional arguments. It allocates a small buffer for up to 5 parameters. But it seems like even if the small buffer is not used, it's still faster.
Use small buffer, total: 2 positional arguments.
haypo@smithers$ ./python -m perf timeit -s 'from functools import partial; f = lambda x, y: None; g = partial(f, 1)' 'g(2)' --duplicate=100 --compare-to ../master-ref/python --python-names=ref:patch --python-names=ref:patch
ref: ..................... 138 ns +- 1 ns
patch: ..................... 121 ns +- 1 ns
Median +- std dev: [ref] 138 ns +- 1 ns -> [patch] 121 ns +- 1 ns: 1.14x faster (-12%)
Don't use small buffer, total: 6 positional arguments.
haypo@smithers$ ./python -m perf timeit -s 'from functools import partial; f = lambda a1, a2, a3, a4, a5, a6: None; g = partial(f, 1, 2, 3, 4, 5)' 'g(6)' --duplicate=100 --compare-to ../master-ref/python --python-names=ref:patch --python-names=ref:patch
ref: ..................... 156 ns +- 1 ns
patch: ..................... 136 ns +- 0 ns
Median +- std dev: [ref] 156 ns +- 1 ns -> [patch] 136 ns +- 0 ns: 1.15x faster (-13%)
Another benchmark with 10 position arguments:
haypo@smithers$ ./python -m perf timeit -s 'from functools import partial; f = lambda a1, a2, a3, a4, a5, a6, a7, a8, a9, a10: None; g = partial(f, 1, 2, 3, 4, 5)' 'g(6, 7, 8, 9, 10)' --duplicate=100 --compare-to ../master-ref/python --python-names=ref:patch --python-names=ref:patch
ref: ..................... 193 ns +- 1 ns
patch: ..................... 166 ns +- 2 ns
Median +- std dev: [ref] 193 ns +- 1 ns -> [patch] 166 ns +- 2 ns: 1.17x faster (-14%) |
|
Date |
User |
Action |
Args |
2017-03-06 13:22:46 | vstinner | set | recipients:
+ vstinner |
2017-03-06 13:22:46 | vstinner | set | messageid: <1488806566.01.0.913410050089.issue29735@psf.upfronthosting.co.za> |
2017-03-06 13:22:45 | vstinner | link | issue29735 messages |
2017-03-06 13:22:45 | vstinner | create | |
|