[PYTHON] Try running Pyston 0.1

About Pyston

Pyston is a compatible implementation of Python 2.7 created with DropBox. It seems that implementation is being promoted to improve performance using LLVM and modern JIT technology. See the following article for details.

 With those caveats, Pyston generally is able to beat CPython’s performance, but still lags behind PyPy.

"Performs better than CPython, but not as good as PyPy."

By the way, it seems that it is currently targeting the platform of Ubuntu + x86_amd64 environment.

Build

At present (as of April 15, 2014), the binary is not published, so you need to build it yourself. You can roughly build it by referring to the following.

Build environment

I tried to build an environment using Vagrant.

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"

Build flow

Almost as documented.

Get the code for Pyston

Get the code from github

$ sudo apt-get install git
$ cd ~/
$ git clone https://github.com/dropbox/pyston.git

Install what depends on Pyston

$ mkdir ~/pyston_deps

Build gcc for clang

$ sudo apt-get install libgmp-dev libmpfr-dev libmpc-dev make build-essential libtool zip gcc-multilib autogen
$ cd ~/pyston_deps
$ wget 'http://www.netgull.com/gcc/releases/gcc-4.8.2/gcc-4.8.2.tar.bz2'
$ tar xvf gcc-4.8.2.tar.bz2
$ mkdir gcc-4.8.2-{build,install}
$ cd gcc-4.8.2-build
$ ../gcc-4.8.2/configure --disable-bootstrap --enable-languages=c,c++ --prefix=$HOME/pyston_deps/gcc-4.8.2-install
$ make -j4
$ make check
$ make install

ccache

$ sudo apt-get install ccache

Add the following line to ~ / pyston / src / Makefile.local when not in use

 USE_CCACHE := 0

Introduced packages required for LLVM build

$ sudo apt-get install libncurses5-dev zlib1g-dev

LLVM + clang

$ cd ~/pyston_deps
$ git clone http://llvm.org/git/llvm.git llvm-trunk
$ git clone http://llvm.org/git/clang.git llvm-trunk/tools/clang
$ cd ~/pyston/src
$ make llvm_up
$ make llvm_configure
$ make llvm -j4

libunwind

$ cd ~/pyston_deps
$ wget http://download.savannah.gnu.org/releases/libunwind/libunwind-1.1.tar.gz
$ tar xvf libunwind-1.1.tar.gz
$ mkdir libunwind-1.1-install
$ cd libunwind-1.1
$ ./configure --prefix=$HOME/pyston_deps/libunwind-1.1-install --enable-shared=0
$ make -j4
$ make install
$ ldconfig

valgrind

According to the Install docs, apt is old, so it says that you should build from source, so I will put it from the sauce obediently.

$ cd ~/pyston_deps
$ wget http://valgrind.org/downloads/valgrind-3.9.0.tar.bz2
$ tar xvf valgrind-3.9.0.tar.bz2
$ mkdir valgrind-3.9.0-install
$ cd valgrind-3.9.0
$ ./configure --prefix=$HOME/pyston_deps/valgrind-3.9.0-install
$ make -j4
$ make install
$ sudo apt-get install libc6-dbg

Then edit ~ / pyston / src / Makefile.local

VALGRIND := VALGRIND_LIB=$(HOME)/pyston_deps/valgrind-3.9.0-install/lib/valgrind $(HOME)/pyston_deps/valgrind-3.9.0-install/bin/valgrind

Regarding Optional dependencies, it is written in Readme.md that you can skip it, so I will omit it here.

(Finally) Pyston build

$ cd ~/pyston/src
$ make check -j4

Various tests run. If the test passes successfully, you will have a binary. Thank you for your hard work.

$ ls ~/pyston/src/pyston*
/home/vagrant/pyston/src/pyston
/home/vagrant/pyston/src/pyston_prof
/home/vagrant/pyston/src/pyston_dbg

starting method

$ ./pyston
  1.9ms to load stdlib
 4.3ms for initCodegen
4.5ms for jit startup
Pyston v0.1, rev 1fe94923ff6f
>>

Vervose mode is standard in Pyston 0.1, so unless you are interested in the process of building to LLVM, add the "q (quiet)" option.

$ ./pyston -q
>>

Read the file into the REPL with the "i" option. By the way, the file cannot be read unless it is in ~ / pyston / src (it falls due to a Segmentation fault).

$ ./pyston -iq hello.py
Hello Pyston v0.1
Pyston v0.1, rev 1fe94923ff6f
>>
print("Hello Pyston v0.1")

It can also be executed from a file.

$ ./pyston -q hello.py
Hello Pyston v0.1

See here for more details.

https://github.com/dropbox/pyston/blob/master/README.md#command-line-options

important point

If you haven't been disappointed so far, read on.

So is it really fast?

So, I did a performance check. The comparison is as follows

Recursion

import time

def fib(n):
    if n < 2: return n
    return fib(n - 2) + fib(n - 1)

if __name__ == "__main__":
    for x in range(3):
        fib(3)

    start = time.time()
    result = fib(38)
    timespan = time.time() - start
    print(result)
    print (timespan)

Python v2.7.3

$ python -i fib.py
39088169
11.7266070843

PyPy v2.2.1

$ ~/pypy-2.2.1-linux64/bin/pypy -i fib.py
39088169
2.00477910042

Pyston v0.1

$ cd ~/pyston/src
$ ./pyston -iq fib.py
39088169
1.37748503685

rec.png

With this kind of feeling, I found that it seems that speedup can be expected for recursive code.

loop

import time

def fib(n):
    value = 0
    f1, f2 = 1, -1
    for i in range(n+1):
        value = f1 + f2
        f2 = f1
        f1 =value

    return value

if __name__ == "__main__":
    for x in range(3):
        fib(3)

    start = time.time()
    result = 0
    for x in range(0,5000):
        result = fib(38)
    timespan = time.time() - start
    print(result)
    print (timespan)

Python v2.7.3

$ python -i fib_loop.py
39088169
0.0174479484558

PyPy v2.2.1

$ ~/pypy-2.2.1-linux64/bin/pypy -i fib_loop.py
39088169
0.0166938304901

Pyston v0.1

$ cd ~/pyston/src
$ ./pyston -iq fib.py
39088169
0.0527310371399

loop.png

Loops are slower than Python.

reference

↑ I referred to the verification code.

that's all.

Recommended Posts

Try running Pyston 0.1
Try running Amazon Timestream
Try running Python with Try Jupyter
Try running Jupyter with VS Code
Try running Jupyter Notebook on Mac
Try python
try pysdl2
Try running PlaidML image judgment on Mac
Regarding Pyston 0.3
Try PyOpenGL
Try running Kobuki's 3D simulator on ROS
Try running Google Chrome with Python and Selenium
Try running Distributed TensorFlow on Google Cloud Platform