pypy

How to set the content of a closure cell?

ぃ、小莉子 提交于 2019-12-25 01:12:42
问题 The following question shows how to create a closure cell object, in order to programmatically construct functions with closures. However, there's a chicken-and-egg problem here where I need to create the cells to create the function, but I may not be able to finalize the values I want the cells to have until after the function is created. (As a mad example, what if I want to put the function itself in one of its cells?) Is there a way to set the cell_contents of a cell? I tried assigning to

Python 2.X中的range和xrange函数之间有什么区别?

狂风中的少年 提交于 2019-12-24 17:27:50
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 显然,xrange更快,但是我不知道为什么它更快(到目前为止,除了轶事之外,还没有证据表明它更快)或除此之外还有什么不同 for i in range(0, 20): for i in xrange(0, 20): #1楼 根据扫描/打印0-N个项目的要求,range和xrange的工作方式如下。 range()-在内存中创建一个新列表,并将整个0到N个项目(总共N + 1个)打印出来。 xrange()-创建一个迭代器实例,该实例扫描项目并仅将当前遇到的项目保留在内存中,因此始终使用相同数量的内存。 如果所需元素只是在列表的开头,那么它可以节省大量时间和内存。 #2楼 我很震惊,没有人读 doc : 此函数与 range() 非常相似,但是返回一个 xrange 对象而不是列表。 这是一种不透明的序列类型,其产生的值与对应的列表相同,而实际上并没有同时存储它们。 xrange() 优于 range() 的优势很小(因为 xrange() 仍然需要在创建值时才创建值),除非在内存不足的计算机上使用了非常大的范围,或者所有范围的元素都在从未使用过(例如,当环路通常与终止 break )。 #3楼 什么? range 在运行时返回静态列表。 xrange 返回一个 object (该 object 行为类似于生成器

Am I using PyPy wrong? It's slower 10x than standard Python

落爺英雄遲暮 提交于 2019-12-23 16:00:57
问题 I have heard good stuff about PyPy. In particular I'd heard that it was very fast which made me wonder if it might be usable for an embedded project I have. I downloaded PyPy-2.6 for my Windows 7 PC, and unzipped the contents into a directory. I've written a small test program to allow me to benchmark: import time def fib(n): if n == 0 or n == 1: return 1 return fib(n - 1) + fib(n - 2) t0 = time.time() fib(20) t1 = time.time() print t1-t0 So I went to the directory where PyPy was unzipped,

Failed to install pip for pypy on Ubuntu

岁酱吖の 提交于 2019-12-23 15:11:01
问题 I cannot install pip for pypy 4.0.1 on Ubuntu 15.10. I downloaded pypy 4.0.1 from http://pypy.org/download.html. Created a symlink for it. And used wget to download get-pip.py from https://bootstrap.pypa.io/get-pip.py. But when I ran sudo pypy get-pip.py , I got exception: 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

pypy import clr fails on Windows

落花浮王杯 提交于 2019-12-23 06:47:39
问题 I tried pythonnet with pypy on Win10. It builds fine, but then fails to import clr . The crash happens after this call in the screenshot. Any tips/tools for debugging this? pypy Python 2.7.12 (aff251e54385, Nov 09 2016, 17:54:55) [PyPy 5.6.0 with MSC v.1500 32 bit] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>> import clr Attempting to load 'Python.Runtime' using standard binding rules. 'Python.Runtime' not found using standard binding rules. Attempting

Counting Algorithm Performance Optimization in Pypy vs Python (Numpy vs List)

半世苍凉 提交于 2019-12-22 06:35:34
问题 My expectation was that pypy could be as much as an order of magnitude faster than python, but the results indicate that pypy is in fact slower than expected. I have two questions: Why is pypy significantly slower with numpy? Is there anything I can do to optimize my algorithm to make pypy (or python) faster? Resulting timings: Python 2.7.5 # points: 16,777,216 (8 ** 3 * 32 ** 3) Xrange time: 1487.15 ms Xrange Numpy time: 2553.98 ms Point Gen Time: 6162.23 ms Numpy Gen Time: 13894.73 ms Pypy

Optimizing for PyPy

流过昼夜 提交于 2019-12-21 04:27:27
问题 (This is a follow-up to Statistical profiler for PyPy) I'm running some Python code under PyPy and would like to optimize it. In Python, I would use statprof or lineprofiler to know which exact lines are causing the slowdown and try to work around them. In PyPy though, both of the tools don't really report sensible results as PyPy might optimize away some lines. I would also prefer not to use cProfile as I find it very difficult to distil which part of the reported function is the bottleneck.

PyPy significantly slower than CPython

孤街醉人 提交于 2019-12-21 03:58:16
问题 I've been testing a cacheing system of my making. Its purpose is to speed up a Django web application. It stores everything in-memory. According to cProfile most of the time in my tests is spent inside QuerySet._clone() which turns out to be terribly inefficient (it's actually not that strange given the implementation). I was having high hopes for using PyPy to speed things up. I've got a 64-bit machine. However after installing all the required libraries it turns out that PyPy compiled code

How can I set up lxml and pypy on Yosemite?

左心房为你撑大大i 提交于 2019-12-20 05:19:06
问题 I wanted to do some learning with lxml and pypy, so I decided to get it set up on my Yosemite Mac. But after three days of trying, I still haven't been able to try lxml, because I can't get my setup right. Here's what I've done: Did a clean homebrew and xcode-select --install install proix:~ user$ brew --version 0.9.5 proix:~ user$ gcc --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 6.0 (clang

PyPy 17x faster than Python. Can Python be sped up?

自古美人都是妖i 提交于 2019-12-20 02:25:32
问题 Solving a recent Advent of Code problem, I found my default Python was ~40x slower than PyPy. I was able to get that down to about 17x with this code by limiting calls to len and limiting global lookups by running it in a function. Right now, e.py runs in 5.162 seconds on python 3.6.3 and .297 seconds on PyPy on my machine. My question is: is this the irreducible speedup of JIT, or is there some way to speed up the CPython answer? (short of extreme means: I could go to Cython/Numba or