BeautifulSoup 与 Jython

发布于 2024-08-09 21:28:25 字数 617 浏览 4 评论 0原文

我刚刚尝试使用 Jython (2.5.1) 运行 BeautifulSoup (3.1.0.1),我惊讶地发现它比 CPython 慢了多少。解析页面 (http://www.fixprotocol.org/specifications/fields/5000- 5999)使用 CPython 只需不到一秒(准确地说是 0.844 秒)。使用 Jython 需要 564 秒——几乎是原来的 700 倍。

有人能证实这个结果吗? Jython 的运行速度比 CPython 慢 700 倍似乎不合理。也许我的设置有问题。

[编辑] 这是我用来测试这个的代码(当然我下载了上面提到的 HTML 文件):

import time
from BeautifulSoup import BeautifulSoup
data = open("fix-5000-5999.html").read()
start = time.time()
soup = BeautifulSoup(data)
print time.time() - start

I just tried to run BeautifulSoup (3.1.0.1) with Jython (2.5.1) and I was amazed to see how much slower it was than CPython. Parsing a page (http://www.fixprotocol.org/specifications/fields/5000-5999) with CPython took just under a second (0.844 second to be exact). With Jython it took 564 seconds - almost 700 times as much.

Can anyone confirm this result? It's doesn't seem reasonable for Jython to run 700 times slower than CPython. Perhaps something is wrong with my setup.

[Edit] Here's the code I used to test this (naturally I downloaded the above mentioned HTML file):

import time
from BeautifulSoup import BeautifulSoup
data = open("fix-5000-5999.html").read()
start = time.time()
soup = BeautifulSoup(data)
print time.time() - start

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随心而道 2024-08-16 21:28:26

我可以证实类似的发现。

英特尔 Mac、OS X 10.6.1、Java 1.6.0_15 64 位、Jython 2.5.1。

使用 CPython 2.6.1 运行代码需要 0.1–0.2 秒,但使用 Jython 运行至少需要数十秒;我没有等超过30。它也使用了大量的CPU。

我尝试了 Beautiful Soup 3.0.7a,因为它使用不同的解析器,但结果相同。

有趣的是,我尝试在 不同的 HTML 文件 上运行您的代码,效果很好。但它看起来仍然比 CPython 慢很多:Jython 花了 1.02-1.3 秒; CPython 的得分为 0.019–0.020。

我目前没有任何建议,除了您应该考虑在 上提出这个问题jython-users 列表;我发现那里的社区(包括首席开发人员)反应灵敏且乐于助人。

祝你好运!

I can confirm similar findings.

Intel Mac, OS X 10.6.1, Java 1.6.0_15 64-bit, Jython 2.5.1.

Running your code with CPython 2.6.1 takes 0.1–0.2 seconds, but running it with Jython takes at least tens of seconds; I didn't wait more than 30. It also uses a lot of CPU.

I tried Beautiful Soup 3.0.7a, because it uses a different parser, but had the same results.

Interestingly, I tried running your code on a different HTML file and it worked fine. But it still seemed much slower than CPython: Jython took 1.02–1.3 seconds; CPython took 0.019–0.020.

I don't have any suggestions at this point except that you should consider asking this question on the jython-users list; I've found the community there, which includes the lead developer, to be responsive and helpful.

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文