Skip to content

Conversation

v1k1nghawk
Copy link

Type of Change

feature + code quality improvements
API changed or not: no

Description

Reduce the performance impact of dictionaries creation and lists building (plus remove import duplication and improve formatting).

How has this PR been tested?

list comprehension vs list():

python3 -m timeit --number=10000000 "
[l for l in 'data']
"

10000000 loops, best of 5: 401 nsec per loop

python3 -m timeit --number=10000000 "
list('data')
"

10000000 loops, best of 5: 326 nsec per loop

dict() vs {}:

python3 -m timeit --number=10000000 "
dict()
"

10000000 loops, best of 5: 139 nsec per loop

python3 -m timeit --number=10000000 "
{}
"

10000000 loops, best of 5: 65.4 nsec per loop

Setup:

  • Python 3.12.3
  • Linux 6.8.9-300.fc40.x86_64

Dependency Change?

any library dependency introduced or removed: no

@justinchuby
Copy link
Member

All of these changes can be auto-fixed by ruff. I suggest we wait and use the tool to fix everything, once the CI pipeline is set up.

Sign up for free to 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.

2 participants