-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Why zip is slower than list comprehension when list is very long? #102724
Comments
Mostly because of the garbage collection cost caused by the gc enabled:
gc disabled:
|
I would suggest using
|
@picnixz I think that's improper. The legitimate reason that timeit disables garbage collection is to remove effects of garbage collection caused by unrelated code. But in this case, it's caused by the code in question. The timeit documentation also says:
And if you want to make it faster by disabling garbage collection, then disable it explicitly, not by using a timing method that does it for you. You don't use timeit to run code in production, after all. |
@picnixz Also, you timed only |
Thank you for pinpointing this (I actually don't suggest disabling the garbage collection using
Well, that's what the OP essentially marked as being slow (consuming the zip iterator does not dominate the complexity in this case). |
Ok, though it doesn't really time "performance" but "performance with disabled garbage collection". Which isn't really realistic/meaningful unless their actual usage also is with disabled garbage collection. |
Sorry, I removed my wrong observation. I close this issue because it is duplicate of #100403. |
Bug report
I have found that
zip
is much slower than list comprehension when the list is very long.This issue is same as lululxvi/deepxde#1149
Your environment
The text was updated successfully, but these errors were encountered: