Presented at rocpy by @ralphbean.
Slides available at http://threebean.org/presentations/pypy/
_ = ( 255, lambda V ,B,c :c and Y(V*V+B,B, c -1)if(abs(V)<6)else ( 2+c-4*abs(V)**-0.4)/i ) ;v, x=1500,1000;C=range(v*x );import struct;P=struct.pack;M,\ j ='<QIIHHHH',open('M.bmp','wb').write for X in j('BM'+P(M,v*x*3+26,26,12,v,x,1,24))or C: i ,Y=_;j(P('BBB',*(lambda T:(T*80+T**9 *i-950*T **99,T*70-880*T**18+701* T **9 ,T*i**(1-T**45*2)))(sum( [ Y(0,(A%3/3.+X%v+(X/v+ A/3/3.-x/2)/1j)*2.5 /x -2.7,i)**2 for \ A in C [:9]]) /9) ) )
$ time python mandelbrot.py
python mandelbrot.py 260.94s user 0.09s system 99% cpu 4:21.20 total
$ time pypy mandelbrot.py
pypy mandelbrot.py 68.74s user 0.07s system 99% cpu 1:08.91 total
That's 3.8 times faster.
How would I explain this to my mom?
How could I possibly explain this to her?
$ hg clone https://bitbucket.org/pypy/pypy
$ cd pypy
We can run the interpreter, as written in python.
$ cd pypy/bin
$ python pypy_interact
It's super slow.
What does that even mean?
$ python rpython/bin/rpython -Ojit pypy/goal/targetpypystandalone.py
That thing is rewriting pypy as c code (millions of lines of code)
So, while that's building...
Specifically some fibonacci code.
Does the translator operate on python source, i.e. .py files?
Is there a parser for that? An AST handler? Lex, etc?
It operates on bytecode.
consider:
>>> import os >>> os.path.abspath <function abspath at 0x7f413cd39a28> >>> os.path.abspath.__code__.co_code 't\x00\x00|\x00\x00\x83\x01\x00sH\x00t\x01\x00|\x00\x00t\x02\x00\x83\x02\x00r*\x 00t\x03\x00j\x04\x00\x83\x00\x00}\x01\x00n\x0c\x00t\x03\x00j\x05\x00\x83\x00\x00 }\x01\x00t\x06\x00|\x01\x00|\x00\x00\x83\x02\x00}\x00\x00n\x00\x00t\x07\x00|\x00 \x00\x83\x01\x00S'
but the implications are crazy. Look at this. This is CPython, the one you know and love.
There's a lot more to it, but it basically boils down to this.
It is basically the same, but written in Python
OK, it's not really the same. There's a JIT in there, but bear with me.
They got to re-use the bytecode interpreter from pypy in the translation process.
pypy translates itself into C, using itself.
I'm out.
The translation toolchain is the coolest part.
Then again, there are neat things in the pypy implementation itself, like the JIT which I don't understand.
FWIW, the translation toolchain allows other things to be implemented in rpython, and translated to C, like topaz.
Presented at rocpy by @ralphbean.
Slides available at http://threebean.org/presentations/pypy/
Space | Forward |
---|---|
Left, Down, Page Down | Next slide |
Right, Up, Page Up | Previous slide |
P | Open presenter console |
H | Toggle this help |