Skip to content

Conversation

@eendebakpt
Copy link
Contributor

@eendebakpteendebakpt commented Oct 12, 2025

Benchmark:

import pyperf runner = pyperf.Runner() setup=""" d ={ii: ii+1 for ii in range(200)} dct_items = d.items() """ runner.timeit(name="extend list with dict keys", stmt="l = []; l += d", setup=setup) runner.timeit(name="extend list with dict items", stmt="l = []; l += dct_items", setup=setup) 

Results:

extend list with dict items: Mean +- std dev: [main] 3.78 us +- 0.07 us -> [pr] 3.17 us +- 0.03 us: 1.19x faster Benchmark hidden because not significant (1): extend list with dict keys Geometric mean: 1.09x faster 

The benchmark is 19% faster (extend list with dict keys is a control benchmark).

@kumaraditya303kumaraditya303 merged commit e6aa515 into python:mainOct 13, 2025
49 checks passed
@vstinner
Copy link
Member

If PyTuple_Pack() is "inefficient", I would prefer to have a specialized PyTuple_Pack2() function (or PyTuple_MakePair()) rather than having to use the generic PyTuple_FromArray().

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@eendebakpt@vstinner@kumaraditya303