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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Speed up your Python using Rust

291 点作者 jD91mZM2超过 7 年前

11 条评论

emj超过 7 年前
About as fast as numpy.. More tools to create fast code is always great, but the tooling for Rust&#x2F;C in Python needs to be easier, I just can&#x27;t be bothered most of the time.<p>This in numpy gets a better relative boost on my machine YMMV.<p><pre><code> import numpy def count_double_chars_np(val): ng=np.fromstring(val,dtype=np.byte) return np.sum(ng[:-1]==ng[1:]) def test_np(benchmark): benchmark(count_double_chars_np, val)</code></pre>
评论 #15721465 未加载
评论 #15721765 未加载
js2超过 7 年前
See also “Fixing Python Performance With Rust” previously discussed here:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12748020" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=12748020</a><p>And “Evolving Our Rust With Milksnake”:<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15697570" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=15697570</a><p>Both from Armin Ronacher at Sentry. About Milksnake:<p><i>Milksnake helps you compile and ship shared libraries that do not link against libpython either directly or indirectly. This means it generates a very specific type of Python wheel. Since the extension modules do not link against libpython they are completely Python version or implementation independent. The same wheel works for Python 2.7, 3.6 or PyPy. As such if you use milksnake you only need to build one wheel per platform and CPU architecture.</i>
评论 #15722640 未加载
Dowwie超过 7 年前
I never got around to talking about it, but as part of my &quot;month of Rust&quot;, I ported permission-based authorization logic from Python to Rust and then ran performance benchmarks of the Rust implementation and a pypy-compiled version. The pypy-compiled python ran slightly faster.<p>I&#x27;ve been told not to expect similar results in other implementations. These findings cannot be used to draw any conclusions about pypy.<p>My rust project: <a href="https:&#x2F;&#x2F;github.com&#x2F;YosaiProject&#x2F;yosai_libauthz" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;YosaiProject&#x2F;yosai_libauthz</a>
评论 #15723808 未加载
评论 #15726683 未加载
评论 #15723985 未加载
Matumio超过 7 年前
For comparison, I just implemented the same as C SWIG extension[1]. It&#x27;s about 10% faster, but it&#x27;s cheating by comparing bytes instead of utf-8 encoded characters. The more interesting part to me is the comparison of the amount of boilerplate code required.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;martinxyz&#x2F;rust-python-example&#x2F;commit&#x2F;f8e36ab5f9c" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;martinxyz&#x2F;rust-python-example&#x2F;commit&#x2F;f8e3...</a>
评论 #15721714 未加载
评论 #15721946 未加载
评论 #15724039 未加载
评论 #15721083 未加载
评论 #15722437 未加载
评论 #15721026 未加载
vog超过 7 年前
I like the article, but the following advice confused me, especially since this comes from RedHat i.e. Linux people:<p><i>&gt; Having Rust installed (recommended way is <a href="https:&#x2F;&#x2F;www.rustup.rs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.rustup.rs&#x2F;</a>).</i><p>This essentially recommends unconditionally using the &quot;curl | sh&quot; anti-pattern.<p>Shouldn&#x27;t they recommend instead e.g. &quot;apt-get install rustc&quot; for Debian users?<p>Since this doesn&#x27;t make use of too recent Rust features, using Rust 1.14 of Debian&#x2F;Stable should be fine, shouldn&#x27;t it? Same of Fedora, etc.
评论 #15720791 未加载
评论 #15720794 未加载
评论 #15721388 未加载
评论 #15721909 未加载
评论 #15720749 未加载
评论 #15720835 未加载
评论 #15720798 未加载
评论 #15733038 未加载
评论 #15721402 未加载
b0rsuk超过 7 年前
&gt; Rust is a language that, because it has no runtime, can be used to integrate with any runtime; you can write a native extension in Rust that is called by a program node.js, or by a python program, or by a program in ruby, lua etc. and, however, you can script a program in Rust using these languages. — “Elias Gabriel Amaral da Silva”<p>Can someone explain why is &quot;having a runtime&quot; problematic for writing extensions and calling them from Python ? From what I gather Go does have a runtime, so implicitly it should be suboptimal for calling from Python. Yet since 2015 (Go 1.5) can be called directly from Python. I&#x27;m a Python programmer looking to expand my tool belt. I&#x27;m wondering of relative pros and cons of Rust and Go. I have only written small toy programs in C and other compiled languages.<p>Is Go better suited to completely rewriting software rather than using it for extensions ? Why ?<p>I would appreciate a benchmark with a Go extension, too.
评论 #15721455 未加载
评论 #15722047 未加载
评论 #15722591 未加载
评论 #15721321 未加载
onnnon超过 7 年前
If anyone is looking for something like this for Ruby, check out Helix:<p><a href="https:&#x2F;&#x2F;usehelix.com" rel="nofollow">https:&#x2F;&#x2F;usehelix.com</a>
评论 #15733603 未加载
pmoriarty超过 7 年前
What&#x27;s the advantage of doing this over using cython or pypy?
评论 #15720154 未加载
评论 #15720388 未加载
rochacbruno超过 7 年前
Now we got Numba, Cython and Numpy results for comparison <a href="https:&#x2F;&#x2F;github.com&#x2F;rochacbruno&#x2F;rust-python-example#new-results" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rochacbruno&#x2F;rust-python-example#new-resul...</a>
j_s超过 7 年前
<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=14588333" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=14588333</a> (beautifulsoup&#x2F;lxml upgrade)<p>&gt;<i>Python: interactive glue language between high performance C libraries.</i><p>Appreciate this walkthrough for Rust!
评论 #15725713 未加载
pbreit超过 7 年前
Shouldn&#x27;t Python, et al have more &quot;native&quot; ways to achieve these sorts of performance improvements?
评论 #15725686 未加载