TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

3 点作者 sohkamyung2 个月前

2 条评论

zahlman2 个月前
&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 个月前
The explanation is paywalled.<p>&gt; This post is for paid subscribers.