pypy

谁是速度之王(Python vs JavaScript)?

天大地大妈咪最大 提交于 2019-12-02 06:12:15
Python 是个比较成熟的语言,运行速度在几年前是快于 JavaScript 的。但这些年 JavaScript 的解释器发展很快,特别是 Google 的 V8 和 Mozilla 的 SpiderMonkey, 将 JavaScript 的运行速度提升了一大块,以致 JavaScript 的运行速度大有反超 Python 之势,但 Python 也不甘示弱,PyPy 项目经过几年的开发之后,最近也在频频发布版本, 将 JIT 带到 Python 之中,所以谁比谁牛,还很难说。这里做个简单的测试: 测试环境: CPU: Intel(R) Pentium(R) CPU G620 @ 2.60GHz 双核 操作系统: Debian GNU/Linux 6.0 64 位 Google JS 引擎: 来自 Node.js v0.6.12 (命令:node) Mozilla JS 引擎:来自 xulrunner-11.0 (命令:xpcshell) Python: Debian 自带的 Python 2.6.6 (命令:python) PyPy: pypy-1.8 (命令:pypy) 先测试简单的循环累加,测试代码: testSum.js var i, j, s; for (i = 0; i < 100; i++) { s = 0; for (j = 0; j < 100000; j++

PyPy displaying inaccurate benchmark results?

会有一股神秘感。 提交于 2019-12-02 03:31:11
问题 I was working on Project Euler and wondered if I could speed up my solution using PyPy. However, I found results quite disappointing, as it took more time to compute. d:\projeuler>pypy problem204.py 3462.08630405 mseconds d:\projeuler>python problem204.py 1823.91602542 mseconds Since mseconds output were calculated using python's time modules, so I ran it again using builtin benchmark commands. d:\projeuler>pypy -mtimeit -s "import problem204" "problem204._main()" 10 loops, best of 3: 465

is there any alternative to sys.getsizeof() in PyPy?

安稳与你 提交于 2019-11-30 17:11:46
问题 I am trying to run a Python (2.7) script with PyPy but I have encountered the following error: TypeError: sys.getsizeof() is not implemented on PyPy. A memory profiler using this function is most likely to give results inconsistent with reality on PyPy. It would be possible to have sys.getsizeof() return a number (with enough work), but that may or may not represent how much memory the object uses. It doesn't even make really sense to ask how much *one* object uses, in isolation with the rest

Guidelines to write fast code for PyPy's JIT

天大地大妈咪最大 提交于 2019-11-30 12:45:50
问题 PyPy's JIT can make Python code execute much faster than CPython. Are there a set of guidelines for writing code that can be optimised better by the JIT compiler? For example, Cython can compile some static code into C++, and it has guidelines to write efficient code. Are there a set of good practices for PyPy? I know that the PyPy project has guidelines for including hints while writing your own JIT-enabled interpreters for other dynamic languages, but that is not relevant to most end users

Installing Python eggs under PyPy

不想你离开。 提交于 2019-11-30 08:29:08
How do I install Python egg under PyPy? During installation, PyPy created /usr/lib64/pypy-1.5/site-packages/ directory. So, I tried using easy_install with prefix set to this directory, however it complains that this is not a valid directory for eggs. Do I just copy eggs from /usr/lib/python2.7/site-packages , or is it as easy as using easy_install (with some changes in configuration, perhaps)? My working environment is Fedora 15 Beta, Python 2.7.1 ( /usr/bin/python ), PyPy 1.5.0-alpha0 with GCC 4.6.0 (in /usr/bin/pypy , installed from RPM using yum), easy_install version is: distribute 0.6.14

Install pip on pypy

房东的猫 提交于 2019-11-30 04:53:43
I want to speed up my program so i'm trying to setup pypy + psycopg2cffi. This program opens a xml, parses it and then insert some data in a database. I'm using currently python3, postgresql and psycopg2 but this approaches is really slow. So i want to try run my program with pypy + psycopg2cffi. I have python 3 and pypy, and i want to install psycopg2cffi so i ran this command: pip install psycopg2cffi psycopg2cffi-compat But psycopg2cffi was only installed on python because when i try to import psycopg2cffi on pypy this is the error i get: ImportError: No module named psycopg2cffi So i think

Boolean identity == True vs is True

倖福魔咒の 提交于 2019-11-29 22:07:01
It is standard convention to use if foo is None rather than if foo == None to test if a value is specifically None . If you want to determine whether a value is exactly True (not just a true-like value), is there any reason to use if foo == True rather than if foo is True ? Does this vary between implementations such as CPython (2.x and 3.x), Jython, PyPy, etc.? Example: say True is used as a singleton value that you want to differentiate from the value 'bar' , or any other true-like value: if foo is True: # vs foo == True ... elif foo == 'bar': ... Is there a case where using if foo is True

how can i use pip with pypy installed from launchpad?

旧巷老猫 提交于 2019-11-29 20:38:04
I have ubuntu 11.10. I apt-get installed pypy from this launchpad repository: https://launchpad.net/~pypy the computer already has python on it, and python has its own pip. How can I install pip for pypy and how can I use it differently from that of python? xubuntix Quoting (with minor changes) from here the pypy website : If you want to install 3rd party libraries, the most convenient way is to install pip: $ curl -O https://bootstrap.pypa.io/get-pip.py $ ./pypy-2.1/bin/pypy get-pip.py $ ./pypy-2.1/bin/pip install pygments # for example In order to use it nicely, you might want to add an

Eventlet or gevent or Stackless + Twisted, Pylons, Django and SQL Alchemy

≯℡__Kan透↙ 提交于 2019-11-29 19:20:21
We're using Twisted extensively for apps requiring a great deal of asynchronous io. There are some cases where stuff is cpu bound instead and for that we spawn a pool of processes to do the work and have a system for managing these across multiple servers as well - all done in Twisted. Works great. The problem is that it's hard to bring new team members up to speed. Writing asynchronous code in Twisted requires a near vertical learning curve. It's as if humans just don't think that way naturally. We're considering a mixed approach perhaps. Maybe keep the xmlrpc server part and process

Making python quit program instantly when hitting ESC

好久不见. 提交于 2019-11-29 18:12:50
I'm making an algorithm that reads input from keyboard, stores it on a variable called message and then write this variable into a file. However, whenever the user is typing, if he hits the ESC key, I'd like the execution to stop without any errors. Let's say the code is: message = raw_input() What do I have to add? So if I'm in the middle of a sentence like: My name is th And I hit ESC, it stops? There is no way to do this with normal input. raw_input reads a whole line at a time. In some (very few) cases, you can do this: message = '' while True: ch = sys.stdin.read(1) if ch == '\x1b': exit