我必须使用 Python3(PyPy 实现)分析大量数据,其中我对相当大的浮点数进行一些操作,并且必须检查结果是否足够接近整数。
举个例子,假设我正在生成随机的数字对,并检查它们是否形成毕达哥拉斯三元组(是具有整数边的直角三角形的边):
from math import hypot
from pprint import pprint
from random import randrange
from time import time
def gen_rand_tuples(start, stop, amount):
'''
Generates random integer pairs and converts them to tuples of floats.
'''
for _ in range(amount):
yield (float(randrange(start, stop)), float(randrange(start, stop)))
t0 = time()
## Results are those pairs that results in integer hypothenuses, or
## at least very close, to within 1e-12.
results = [t for t in gen_rand_tuples(1, 2**32, 10_000_000) if …Run Code Online (Sandbox Code Playgroud) python precision pypy floating-accuracy double-double-arithmetic
我正在从头开始设置一个Web服务器,主要用于使用Python编写webapps.在查看Apache + mod_wsgi的替代方案时,看起来pypy在我打算用于我自己的应用程序的几乎所有内容中都表现得非常好.没有真正有机会正确使用PyPy,我觉得这是一个很好的机会来使用它,因为我不需要服务器是防弹的.
但是,我想在Web服务器上运行一些PHP应用程序以用于管理目的(例如,PHPPgAdmin).是否有一个优雅的解决方案,允许我在像Apache这样的PHP兼容的网络服务器中使用PyPy?或者我将不得不运行CherryPy/Paste或其他WSGI服务器之一,Apache和mod_wsgi在一个单独的端口上提供管理服务?
我似乎无法在Google或SO上找到任何关于让cx_Oracle与PyPy一起工作的信息.有人可以告诉我是否有可能,如果是的话,我怎么能做到这一点?
我希望为现有应用程序带来速度提升,我正在寻找有关可能选项的建议.该应用程序是用Python编写的,使用wxPython,并与之打包py2exe(我只针对Windows平台).应用程序的某些部分是计算密集型的,在解释Python中运行得太慢.我不熟悉C,所以移植部分代码并不是我的选择.
所以我的问题基本上是我清楚地了解我的选项,如下所示,或者我是从错误的方向接近这个?
我想学习python所以我从python站点下载它,我看到其他4种蟒蛇出现:
我真的可以找到它们之间的差异.还有哪一个是最好的开始.
$ ./pypy -O Python 2.7.2 (a3e1b12d1d01, Dec 04 2012, 13:33:26) [PyPy 1.9.1-dev0 with GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. And now for something completely different: `` amd64 and ppc are only available in enterprise version'' >>>> assert 1==2 Traceback (most recent call last): File "", line 1, in AssertionError >>>>
但是当我执行时
$ python -O Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> assert …
如何在PyCharm 4.5.2中使用PyPy作为标准/默认解释器?一切都在Ubunutu 14.10下运行,并且已经安装了pypy.
当我尝试使用pip安装matplotlib时,抛出异常:
In file included from /usr/include/numpy/ndarrayobject.h:26:0,
from src/file_compat.h:7,
from src/ft2font_wrapper.cpp:3:
/usr/include/numpy/__multiarray_api.h: In function ‘int _import_array()’:
/usr/include/numpy/__multiarray_api.h:1686:13: error: ‘NPY_CPU_UNKNOWN_ENDIAN’ was not declared in this scope
if (st == NPY_CPU_UNKNOWN_ENDIAN) {
^
/usr/include/numpy/__multiarray_api.h:1697:13: error: ‘NPY_CPU_LITTLE’ was not declared in this scope
if (st != NPY_CPU_LITTLE) {
^
error: command 'cc' failed with exit status 1
----------------------------------------
Command "/usr/bin/pypy -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-vGxrsz/matplotlib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-oB9gVW-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-vGxrsz/matplotlib
Run Code Online (Sandbox Code Playgroud)
如果我正确理解它的问题在numpy中。我使用以下命令安装它:
pypy …
我有一个需要更快运行的python3脚本,因此我试图在运行raspbian Stretch 4.14的raspberry pi上安装pypy3。
看起来pypy已经预装了,但它的版本是2.7.12,并且无法与我的python3代码一起使用。
我在Google上搜索了很多,但找不到适合我的安装pypy3的说明,很多人建议从二进制文件中进行构建,但是我不确定这意味着什么....或在哪里可以找到正确的ARM体系结构二进制文件。
请帮忙!
代码简单
@count_run_time
def test_while(l: int=0) -> (int, int):
y = 0
x = 0
while x < l:
y += x
x += 1
return x, y
Run Code Online (Sandbox Code Playgroud)
当我使用cpython(Python 3.6.8(v3.6.8:3c6b436a57,Dec 24 2018,02:04:31))运行时
test_while(10**5)
[func: test_while] cost @0.008665s
(100000, 4999950000)
test_while(10**6)
[func: test_while] cost @0.080222s
(1000000, 499999500000)
test_while(10**7)
[func: test_while] cost @0.814199s
(10000000, 49999995000000)
test_while(10**8)
[func: test_while] cost @7.944017s
(100000000, 4999999950000000)
test_while(10**9)
[func: test_while] cost @80.063558s
(1000000000, 499999999500000000)
test_while(10**10)
[func: test_while] cost @851.572578s
(10000000000, 49999999995000000000)
Run Code Online (Sandbox Code Playgroud)
从结果可以看出,随着循环次数的增加,消耗的时间也呈线性增加。
接下来,我尝试在pypy3(Python 3.6.1(784b254d6699,Apr 14 2019,10:22:55),[PyPy 7.1.1-beta0与GCC 4.2.1兼容Apple …
pypy ×10
python ×9
python-3.x ×2
apache ×1
cx-oracle ×1
ironpython ×1
jython ×1
matplotlib ×1
numpy ×1
php ×1
pip ×1
precision ×1
pycharm ×1
raspberry-pi ×1
wsgi ×1