我的理解
C++被编译成机器代码并执行.
Python被编译成字节码
然后执行该字节码
这个执行步骤需要什么?Cpython和PyPy有什么不同?
性能差异在哪里发挥作用?Python的动态类型在性能方面取得了哪些进展?
谢谢!
我无法在 Ubuntu 15.10 上为 pypy 4.0.1 安装 pip。
我从http://pypy.org/download.html下载了 pypy 4.0.1 。为它创建了一个符号链接。并使用 wget 从https://bootstrap.pypa.io/get-pip.py下载 get-pip.py 。
但是当我跑的时候sudo pypy get-pip.py
,我得到了例外:
Collecting pip
Exception:
Traceback (most recent call last):
File "/tmp/tmps2kjCI/pip.zip/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/tmp/tmps2kjCI/pip.zip/pip/commands/install.py", line 294, in run
requirement_set.prepare_files(finder)
File "/tmp/tmps2kjCI/pip.zip/pip/req/req_set.py", line 334, in prepare_files
functools.partial(self._prepare_file, finder))
File "/tmp/tmps2kjCI/pip.zip/pip/req/req_set.py", line 321, in _walk_req_to_install
more_reqs = handler(req_to_install)
File "/opt/pypy-4.0.1-linux64/lib_pypy/_functools.py", line 42, in __call__
return self._func(*(self._args + fargs), **fkeywords)
File "/tmp/tmps2kjCI/pip.zip/pip/req/req_set.py", …
Run Code Online (Sandbox Code Playgroud) 我已经在运行 El Capitan 的 Mac 上安装了 Python 2.7 和 3.5。此外,我将 Sympy 包(通过 pip 安装)与 python 一起使用。我想用 Pypy 运行我的代码(安装自制软件),但似乎 Pypy 没有找到 Sympy 并说:
“没有名为 sympy 的模块”
我根本不是专家,现在不知道该怎么办。Sympy 适用于 python 2 和 3,但不适用于 Pypy。
我感谢每一个答案,提前谢谢你。
我必须读取和解析太大而无法加载到内存中的 .pcap 文件。我目前在离线模式下使用嗅探
sniff(offline=file_in, prn=customAction, store=0)
Run Code Online (Sandbox Code Playgroud)
使用 customAction 函数,大致如下所示:
customAction(packet):
global COUNT
COUNT = COUNT + 1
# do some other stuff that takes practically 0 time
Run Code Online (Sandbox Code Playgroud)
目前,这处理数据包的速度太慢。我已经在“驱动程序”程序中使用子进程在不同内核上同时在多个文件上运行此脚本,但我确实需要提高单核性能。
我尝试使用 pypy,但感到失望的是,使用 pypy 的性能比使用 python3 (anaconda) 的性能好不到 10%。
使用 pypy 运行 50k 数据包的平均时间为 52.54 秒
使用 python3 运行 50k 数据包的平均时间为 56.93 秒
有什么办法可以加快速度吗?
编辑:下面是 cProfile 的结果,您可以看到代码在分析时有点慢,但所有时间都花在 scapy 上。
66054791 function calls (61851423 primitive calls) in 85.482 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
957/1 0.017 0.000 85.483 85.483 …
Run Code Online (Sandbox Code Playgroud) 为了测试 Pypy JIT 明显更快的说法,我编写了一个简单的代码,该代码重复添加两个大小为 1200x1200 的数组。我的代码如下
import numpy as np
import random
a=np.zeros((1200, 1200), dtype=np.float32)
b=np.zeros((1200, 1200), dtype=np.float32)
import timeit
#Start timer
start=timeit.default_timer()
#Initialize the arrays
for j in range(1200):
for k in range(1200):
a[j][k]=random.random()
b[j][k]=random.random()
#Repeatedly add the arrays
for j in range(10):
a=np.add(a,b)
#Stop timer and display the results
stop=timeit.default_timer()
print stop-start
Run Code Online (Sandbox Code Playgroud)
对于普通的 python,执行时间约为 1.2 - 1.5 秒。但是使用 Pypy 它会超过 15 秒吗?同样在上述情况下,我只添加了 10 次数组。如果我将此值增加到 1000,我的计算机将停止响应。我发现这是因为使用 pypy 时几乎消耗了整个 RAM。难道我做错了什么?或者问题是其他的?
我正在寻找将 python 源代码编译成二进制文件。出于性能原因,我通常使用 pypy(我的应用程序使用 pypy 运行得更快)。我从 2012 年找到了这个答案,指出使用任何现有工具(例如 pyinstaller)都无法将 pypy 编译为二进制文件。将 PyPy 编译为 Exe。我不太能理解顶级回应作为解决方案所解释的内容。
我想知道:
现在是否有一种相当简单的方法可以使用 pypy 作为解释器将 python 代码编译为二进制文件?
我实际上并不需要使用 pypy,我只是为了提高性能而使用它。有没有一种合理的方法可以避免使用 pypy 但仍然可以获得类似的性能提升?这仍然需要支持编译为二进制文件。
作为附加说明,我使用 2.7 语法。
我尝试了以下分析器,所有这些都与 pypy (5.8.0) 不兼容:
__itemsize__
,并且根据一些谷歌结果,它无论如何都不会产生有用的结果most_common_types()
返回一个空列表。有没有办法在pypy(相当于objgraph.most_common_types()
)中获取类型列表及其实例的内存使用情况?
我使用 pypy 基础的 Dockerfile 失败,出现 FileNotFoundError: [Errno 2] No such file or directory: 'llvm-config' when install llvmlite,numba 的依赖项,在我的 requirements.txt 中列出
我尝试在 Debian 8 上遵循并更新Python numba / llvmlite此处的说明 - 我无法构建 llvmlite
我的错误更详细:
Building wheels for collected packages: llvmlite
Building wheel for llvmlite (setup.py): started
Building wheel for llvmlite (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/pypy3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ux49fegr/llvmlite/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ux49fegr/llvmlite/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, …
Run Code Online (Sandbox Code Playgroud) 我知道有一个重复的问题,但它是从 2017 年开始的。
我正在尝试在我的 conda 中 pip install matplotlib: pypy3 -mpip install matplotlib
这是我得到的错误 - 由于 SO 限制,我不得不截断日志。
我的理解是matplotlib可以安装在pypy上。这样对吗?如果没有,是否有解决方法?
Collecting matplotlib
Downloading matplotlib-3.3.0.tar.gz (38.8 MB)
|????????????????????????????????| 38.8 MB 264 kB/s
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/pypy3/lib/python3.6/site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/pypy3/lib/python3.6/site-packages (from matplotlib) (1.2.0)
Requirement already satisfied: numpy>=1.15 in /opt/conda/envs/pypy3/lib/python3.6/site-packages (from matplotlib) (1.19.1)
Requirement already satisfied: pillow>=6.2.0 in /opt/conda/envs/pypy3/lib/python3.6/site-packages (from matplotlib) (7.2.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /opt/conda/envs/pypy3/lib/python3.6/site-packages (from matplotlib) (2.4.7)
Requirement already satisfied: python-dateutil>=2.1 in …
Run Code Online (Sandbox Code Playgroud) 我的 Mac 上有一个程序,我认为它太慢了。我想使用 pypy 来加速它。我得到了 pypy 的 mac 二进制发行版,然后运行了./pypy -m pip install ...
. 它说我需要运行 ensurepip。但是当我运行它时,它引发了这个错误:
File "/Users/Andy/Downloads/pypy3.7-v7.3.3-osx64/lib-python/3/runpy.py", line 196, in _run_module_as_main
"__main__", mod_spec)
File "/Users/Andy/Downloads/pypy3.7-v7.3.3-osx64/lib-python/3/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Users/Andy/Downloads/pypy3.7-v7.3.3-osx64/lib-python/3/ensurepip/__main__.py", line 5, in <module>
sys.exit(ensurepip._main())
File "/Users/Andy/Downloads/pypy3.7-v7.3.3-osx64/lib-python/3/ensurepip/__init__.py", line 214, in _main
default_pip=args.default_pip,
File "/Users/Andy/Downloads/pypy3.7-v7.3.3-osx64/lib-python/3/ensurepip/__init__.py", line 127, in _bootstrap
return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
File "/Users/Andy/Downloads/pypy3.7-v7.3.3-osx64/lib-python/3/ensurepip/__init__.py", line 32, in _run_pip
runpy.run_module("pip", run_name="__main__", alter_sys=True)
File "/Users/Andy/Downloads/pypy3.7-v7.3.3-osx64/lib-python/3/runpy.py", line 208, in run_module
return _run_module_code(code, init_globals, …
Run Code Online (Sandbox Code Playgroud)