I used to run Python 3.6.7 in ubuntu. Today, I tried the very new python 3.7.3 but I am a little bit disappointed : It seems to me that 3.7 is slower than 3.6 :
Both versions has been taken from deadsnakes/ppa, and when I run Python benchmark suite, many tests where 3.7 should be faster than 3.6 (dixit speed.python.org), I noticed the opposite :
python 3.6:
[ 1/47] 2to3...
INFO:root:Running `/home/elapouya/tmp/venv36/bin/python -u /home/elapouya/tmp/venv36/lib/python3.6/site-packages/performance/benchmarks/bm_2to3.py --output /tmp/tmp27lejbkn`
.....................
2to3: Mean +- std dev: 319 ms +- 5 ms
[ 2/47] chameleon...
INFO:root:Running `/home/elapouya/tmp/venv36/bin/python -u /home/elapouya/tmp/venv36/lib/python3.6/site-packages/performance/benchmarks/bm_chameleon.py --output /tmp/tmp_jvgzmw7`
.....................
chameleon: Mean +- std dev: 8.99 ms +- 0.13 ms
[ 3/47] chaos...
INFO:root:Running `/home/elapouya/tmp/venv36/bin/python -u /home/elapouya/tmp/venv36/lib/python3.6/site-packages/performance/benchmarks/bm_chaos.py --output /tmp/tmpbpea7n4x`
.....................
chaos: Mean +- std dev: 114 ms +- 2 ms
[ 4/47] crypto_pyaes...
INFO:root:Running `/home/elapouya/tmp/venv36/bin/python -u /home/elapouya/tmp/venv36/lib/python3.6/site-packages/performance/benchmarks/bm_crypto_pyaes.py --output /tmp/tmptbh2r8k1`
.....................
crypto_pyaes: Mean +- std dev: 103 ms +- 1 ms
[ 5/47] deltablue...
INFO:root:Running `/home/elapouya/tmp/venv36/bin/python -u /home/elapouya/tmp/venv36/lib/python3.6/site-packages/performance/benchmarks/bm_deltablue.py --output /tmp/tmpm_fyde6p`
.....................
deltablue: Mean +- std dev: 7.19 ms +- 0.12 ms[1/1]
raytrace...
INFO:root:Running `/home/elapouya/tmp/venv36/bin/python -u /home/elapouya/tmp/venv36/lib/python3.6/site-packages/performance/benchmarks/bm_raytrace.py --output /tmp/tmpeaeg9hxq`
.....................
raytrace: Mean +- std dev: 536 ms +- 8 ms
python 3.7:
[ 1/47] 2to3...
INFO:root:Running `/home/elapouya/tmp/venv37/bin/python -u /home/elapouya/tmp/venv37/lib/python3.7/site-packages/performance/benchmarks/bm_2to3.py --output /tmp/tmp96xnk361`
.....................
2to3: Mean +- std dev: 349 ms +- 4 ms
[ 2/47] chameleon...
INFO:root:Running `/home/elapouya/tmp/venv37/bin/python -u /home/elapouya/tmp/venv37/lib/python3.7/site-packages/performance/benchmarks/bm_chameleon.py --output /tmp/tmpzj3vo0qn`
.....................
chameleon: Mean +- std dev: 11.7 ms +- 0.2 ms
[ 3/47] chaos...
INFO:root:Running `/home/elapouya/tmp/venv37/bin/python -u /home/elapouya/tmp/venv37/lib/python3.7/site-packages/performance/benchmarks/bm_chaos.py --output /tmp/tmp5nfno0s9`
.....................
chaos: Mean +- std dev: 132 ms +- 2 ms
[ 4/47] crypto_pyaes...
INFO:root:Running `/home/elapouya/tmp/venv37/bin/python -u /home/elapouya/tmp/venv37/lib/python3.7/site-packages/performance/benchmarks/bm_crypto_pyaes.py --output /tmp/tmpq3mv75iz`
.....................
crypto_pyaes: Mean +- std dev: 124 ms +- 2 ms
[ 5/47] deltablue...
INFO:root:Running `/home/elapouya/tmp/venv37/bin/python -u /home/elapouya/tmp/venv37/lib/python3.7/site-packages/performance/benchmarks/bm_deltablue.py --output /tmp/tmp01whaidm`
.....................
deltablue: Mean +- std dev: 8.93 ms +- 0.15 ms
[ 6/47] django_template...
[1/1] raytrace...
INFO:root:Running `/home/elapouya/tmp/venv37/bin/python -u /home/elapouya/tmp/venv37/lib/python3.7/site-packages/performance/benchmarks/bm_raytrace.py --output /tmp/tmpce_59p1p`
.....................
raytrace: Mean +- std dev: 603 ms +- 12 ms
I also tried to compile python 3.7.3 source code (with --enable-optimizations), but it is not really faster.
Where I am wrong ? why, with official benchmark suite I ran, python3.7 is not faster than 3.6 unlike speed.python.org says ?
答案 0 :(得分:3)
通过查看所有3.6和3.7版本的构建日志,发现3.6版本在CFLAGS中具有-O2,而3.7中没有。那可能就是差异。在发现我作为项目基准的大型操作的性能急剧下降之后,我只需要在RPi上重新编译3.7.3。
使用股票3.5.3,它可以在139秒内完成10 ^ 6整数的基数排序;全新安装了3.7.3,使用--enable-optimizations更改为765秒。将CFLAGS和config args匹配到3.5.3安装后,排序时间降低到143秒。我相信大部分原因是分别由于CFLAGS和config args中的-O2和--enable-computing-gotos造成的。
您可以通过下载3.7.3源代码并使用-O2和--enable-computed-gotos进行altinstall来找出答案。
编辑:10 ^ 6整数,而不是10 ^ 7。