Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed optimizations #79

Open
miron opened this issue Apr 17, 2023 · 0 comments
Open

Speed optimizations #79

miron opened this issue Apr 17, 2023 · 0 comments

Comments

@miron
Copy link
Owner

miron commented Apr 17, 2023

Check for string concatenation

Replace with list.append() and then ‘’.join(list) (O(N) instead of O(N^2))
Alternatively:
list comprehension, generator expression, map, itertools, array.array(‘u’), bytearray, io.TextIO, io.BytesIO or writelines() the list to file, or directly write() strings to file.
Also f’’ 2x faster format() 2x faster str + str

Check for global variables

Replace with local ones, which are faster, also hoist attribute lookups outside of loops (if method doesn’t change object), by assigning to variable for speed improvement (modest speed improvement also for builtins when assigned to local namespace).

Replace loops

Use list comprehensions, generator expressions, map and filter (only with builtins, not lambda) instead.

@miron miron changed the title check for string concatenation Speed optimizations Apr 17, 2023
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

No branches or pull requests

1 participant