简体   繁体   English

Yocto中的Python 3在Raspberry Pi上非常慢

[英]Python 3 in Yocto very slow on Raspberry Pi

We've used Python 2 for an embedded application that we're currently prototyping on Raspberry Pi. 我们使用Python 2作为嵌入式应用程序,我们目前正在Raspberry Pi上进行原型设计。 It's been a bit slow, but acceptable. 它有点慢,但可以接受。

Now we've ported the application to Python 3. But for some reason the application runs about 4 times slower than with Python 2! 现在我们已经将应用程序移植到Python 3.但由于某种原因,应用程序运行速度比使用Python 2慢大约4倍! I was expecting Python 3 to be a bit slower, but nothing like this! 我期待Python 3有点慢,但不是这样的!

Our Linux distribution is based on Yocto 2.2 Morty and we are using the default Python 3.5.2 recipe with no customizations. 我们的Linux发行版基于Yocto 2.2 Morty,我们使用默认的Python 3.5.2配方,没有自定义。 We are also using the meta-raspberrypi layer for Raspberry compatibility. 我们还使用了meta-raspberrypi层来实现Raspberry兼容性。

I tried to time "pip3 --help" and got the following result: 我试着计时“pip3 --help”并得到以下结果:

$ time pip3 --help >/dev/null

real    0m22.686s
user    0m22.210s
sys     0m0.420s

Then I tried the same test on the same hardware (same sd card as well) using the latest Raspbian distro: 然后我使用最新的Raspbian发行版在相同的硬件(同样的SD卡)上尝试相同的测试:

$ time pip3 --help >/dev/null

real    0m6.874s
user    0m6.530s
sys     0m0.310s

$ time pip --help >/dev/null

real    0m4.329s
user    0m4.000s
sys     0m0.300s

Python 2 pip is a little bit faster than Python 3, but the most important thing is that pip3 runs more than 3 times faster on Raspbian than on Yocto! Python 2点比Python 3快一点,但最重要的是pip3在Raspbian上的运行速度比在Yocto上快3倍!

The tests are very repeatable, so they are not caused by pyc-generation or caching or something like that. 测试是非常可重复的,因此它们不是由pyc生成或缓存或类似的东西引起的。

Any ideas how to get Yocto as fast as Raspbian? 有任何想法如何让Yocto像Raspbian一样快?

Update: 更新:

There was some discussions about different versions of Python and Pip in Raspbian vs Yocto below, so I made a new benchmark using only Python standard libraries: 下面有一些关于Raspbian与Yocto中不同版本的Python和Pip的讨论,所以我仅使用Python标准库创建了一个新的基准:

Yocto 2.2 Morty: Yocto 2.2 Morty:

sh-4.3# time python3 --version
Python 3.5.2

real    0m0.024s
user    0m0.010s
sys     0m0.000s
sh-4.3# time python3 -c "import asyncio"

real    0m3.439s
user    0m3.300s
sys     0m0.110s

Raspbian: Raspbian:

pi@raspberrypi:~$ time python3 --version
Python 3.4.2

real    0m0.020s
user    0m0.000s
sys     0m0.010s
pi@raspberrypi:~$ time python3 -c "import asyncio"

real    0m2.023s
user    0m1.850s
sys     0m0.160s

I then downloaded Python 3.5.2 on Raspbian and built it from source, with no custom configuration ( ./configure; make; make install ). 然后我在Raspbian上下载了Python 3.5.2并从源代码构建它,没有自定义配置( ./configure; make; make install )。 With Python 3.5.2 I get the following result: 使用Python 3.5.2,我得到以下结果:

pi@raspberrypi:~$ time python3.5 --version
Python 3.5.2

real    0m0.018s
user    0m0.000s
sys     0m0.010s
pi@raspberrypi:~$ time python3.5 -c "import asyncio"

real    0m2.689s
user    0m2.610s
sys     0m0.070s

So it seems that Python 3.5 is considerably slower than 3.4, but still much, much slower on a default Yocto build than on Raspbian with the default build configuration. 因此,似乎Python 3.5比3.4慢得多,但是在默认的Yocto构建上比使用默认构建配置的Raspbian慢得多。

Update 2: 更新2:

I built Python 3.5.2 the same way on my Yocto system ("./configure; make; make install") and got about 20% improvement compared to the standard Python recipe: 我在Yocto系统上以相同的方式构建了Python 3.5.2(“./configure; make; make install”),与标准的Python配方相比,它提高了约20%:

root@la:/var/src/Python-3.5.2# time python3.5 -c "import asyncio"

real    0m2.914s
user    0m2.750s
sys     0m0.130s

Yocto Python 2 is compiled in optimized mode . Yocto Python 2以优化模式编译。 Try configuring Python 3 (3.5.3+ I think) with ./configure --enable-optimizations as also discussed here . 尝试使用./configure --enable-optimizations配置Python 3(我认为3.5.3+),这也在这里讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM