TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Python Performance: Why 'if not list' is 2x Faster Than Using len()

3 pointsby sohkamyung2 months ago

2 comments

zahlman2 months ago
&gt; But this isn’t just about coding style, one of these is ~2x faster than the other, see for yourself:<p>FWIW, it&#x27;s not necessary to start an interpreter for this test.<p><pre><code> $ py3.13 -m timeit --setup &quot;l = []&quot; &quot;not l&quot; 10000000 loops, best of 5: 20.7 nsec per loop $ py3.13 -m timeit --setup &quot;l = []&quot; &quot;len(l) == 0&quot; 10000000 loops, best of 5: 31 nsec per loop</code></pre>
odie55332 months ago
The explanation is paywalled.<p>&gt; This post is for paid subscribers.