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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Optimizing Python – A Case Study

127 点作者 dpmehta02将近 10 年前

6 条评论

vosper将近 10 年前
He&#x27;s missing Cython, which is another good option when you&#x27;re looking for speed.<p>My personal favourite optimisation, from needing to shave a few milliseconds off our API response times, was discovering that it&#x27;s measurably slower to use * args and * *kwargs, and switching to explicitly declaring and passing arguments in the relevant parts of the code.<p>We also did a few other neat things:<p>- Rolled our own UUID-like generator in pure Python (I was surprised this helped, but the profiler doesn&#x27;t lie)<p>- Switched to working directly with WebOb Request and Response objects rather than using a framework<p>- Used a background thread with a single slot queue to make sure our response was returned to the user before we emitted the event log message, but always emit the message before moving to the next request<p>- Heavy optimisation of memcache &#x2F; redis reads and writes<p>Edit: Fixed formatting
评论 #9622667 未加载
sitkack将近 10 年前
The order of tactics to take is wrong. In terms of energy expended, one should use PyPy first! It is amazingly compatible with CPython and can now be embedded directly in CPython programs, <a href="https:&#x2F;&#x2F;github.com&#x2F;fijal&#x2F;jitpy" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;fijal&#x2F;jitpy</a> (supports numpy arrays)<p>Dump your virtualenv, create a new one with pypy, reinstall libraries and test your app. Takes less than 20 minutes, even for complex applications.
评论 #9623092 未加载
评论 #9622966 未加载
评论 #9626370 未加载
clickok将近 10 年前
Serious question: if you have some code that really has to be fast, is it viable to keep it in Python, or should you ultimately end up rewriting it in a compiled language?<p>For example, I am writing code that implements networks that evolve over time for AI research. Prototyping it in Python makes it easy to test things out, but I expect that I will have to rewrite it in C++ or maybe something more fun, like Haskell[1].<p>1. Mostly for the sheer joy of trolling my colleagues with a learning agent monad.
评论 #9622487 未加载
评论 #9622941 未加载
评论 #9623191 未加载
评论 #9624774 未加载
评论 #9622734 未加载
pepijndevos将近 10 年前
&gt; Think for a second: time is only ever going to increase<p>Well, most of the time at least. Think about DST and leap seconds.
评论 #9626400 未加载
mangeletti将近 10 年前
Isn&#x27;t Jython <i>not</i> a JIT compiler, and isn&#x27;t Jython much slower than cPython?
评论 #9622287 未加载
评论 #9622217 未加载
评论 #9622488 未加载
aburan28将近 10 年前
Pythran is also missing
评论 #9624715 未加载