218
Python Performance: Why 'if not list' is 2x Faster Than Using len()
(blog.codingconfessions.com)
This is a most excellent place for technology news and articles.
I haven't read the article. But I'd assume this is for the same reason that not not string
is faster than bool(string)
. Which is to say that it has to do with having to look up a global function rather than a known keyword.
Isn't it because list is linked list, so to get the Len it has to iterate over the whole list whereas to get emptyness it just have to check if there is a 1st element ?
I' too lazy to read the article BTW.