Python Performance: Why 'if not list' is 2x Faster Than Using len()
Python Performance: Why 'if not list' is 2x Faster Than Using len()
blog.codingconfessions.com Python Performance: Why 'if not list' is 2x Faster Than Using len()
Discover why 'if not mylist' is twice as fast as 'len(mylist) == 0' by examining CPython's VM instructions and object memory access patterns.

You're viewing a single thread.
All comments
111
comments
There are decades of articles on c++ optimizations, that say "use empty() instead of size()", which is same as here.
15 0 Replyexcept for c++ it was just to avoid a single function call, not extra indirection. also on modern compilers size() will get inlined and ultimate instructions generated by the compiler will likely be the same
5 0 Reply
111
comments
Scroll to top