Psyco
Encyclopedia
Psyco is a specializing
just-in-time compiler for Python
originally developed by Armin Rigo and further maintained and developed by Christian Tismer.
Psyco runs on BSD-derived operating systems, Linux
, Mac OS X
and Microsoft Windows
using 32-bit
Intel-compatible processors. Psyco is written in C
and generates only x86-based code. A follow-up project to Psyco is PyPy
, which incorporates an interpreter and a compiler that can generate C, improving its cross-platform compatibility over Psyco. Both parts are written in Python, but the interpreter is restricted to a subset of Python, called RPython.
The average speed improvement is typically in the 1.5-4x range, making Python performance close to languages such as Smalltalk
and Scheme, but still slower than compiled languages such as Fortran
, C
or some other JIT languages like C# and Java
.
Psyco also advertises its ease of use: the simplest Psyco optimization involves adding only two lines to the top of a script:
These commands will import the psyco module, and have Psyco optimize the entire script. This approach is best suited to shorter scripts, but demonstrates the minimal amount of work needed to begin applying Psyco optimizations to an existing program.
Run-time algorithm specialisation
In computer science, run-time algorithm specialization is a methodology for creating efficient algorithms for costly computation tasks of certain kinds...
just-in-time compiler for Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
originally developed by Armin Rigo and further maintained and developed by Christian Tismer.
Psyco runs on BSD-derived operating systems, Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
, Mac OS X
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
and Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
using 32-bit
32-bit
The range of integer values that can be stored in 32 bits is 0 through 4,294,967,295. Hence, a processor with 32-bit memory addresses can directly access 4 GB of byte-addressable memory....
Intel-compatible processors. Psyco is written in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and generates only x86-based code. A follow-up project to Psyco is PyPy
PyPy
PyPy is a Python interpreter and JIT compiler. PyPy focuses on speed, efficiency and 100% compatibility with the original CPython interpreter.- Details and motivation :...
, which incorporates an interpreter and a compiler that can generate C, improving its cross-platform compatibility over Psyco. Both parts are written in Python, but the interpreter is restricted to a subset of Python, called RPython.
Speed enhancement
Psyco can noticeably speed up CPU-bound applications. The actual performance depends greatly on the application and varies from a slight slowdown to a 100x speedup.The average speed improvement is typically in the 1.5-4x range, making Python performance close to languages such as Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...
and Scheme, but still slower than compiled languages such as Fortran
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...
, C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
or some other JIT languages like C# and Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
.
Psyco also advertises its ease of use: the simplest Psyco optimization involves adding only two lines to the top of a script:
import psyco
psyco.full
These commands will import the psyco module, and have Psyco optimize the entire script. This approach is best suited to shorter scripts, but demonstrates the minimal amount of work needed to begin applying Psyco optimizations to an existing program.
See also
- CythonCythonCython is a programming language to simplify writing C and C++ extension modules for the CPython Python runtime. Strictly speaking, Cython syntax is a superset of Python syntax additionally supporting:...
- PyPyPyPyPyPy is a Python interpreter and JIT compiler. PyPy focuses on speed, efficiency and 100% compatibility with the original CPython interpreter.- Details and motivation :...
- Unladen SwallowUnladen SwallowUnladen Swallow was an optimization branch of CPython, intended to be fully compatible and significantly faster. It aimed to achieve its goals by supplementing CPython's custom virtual machine with a JIT built using LLVM. The project had stated a goal of a five-times speed improvement over CPython...
- YARVYARVYARV is a bytecode interpreter that was developed for the Ruby programming language by Koichi Sasada. The goal of the project was to greatly reduce the execution time of Ruby programs....
(Yet another Ruby VM)
External links
- The Psyco home page
- David Mertz's IBM developerWorksDeveloperWorksdeveloperWorks is a free web-based professional network and technical resource center from IBM for software developers, IT professionals, and students worldwide...
article: Make Python run as fast as C with Psyco - psyco notes, Poor Yorick