pypy 1.0 first try
I'm not going to explain too much pypy, I'll just list my instructions on C version PyPy 1.0 + jit (pypy-c with jit) build.
* you may need install these first *
apt-get install
gcc libc6-dev make autoconf libgc-dev bzip2
subversion python2.4 python2.4-dev
python-ctypes python-pygame
Note: you don't really need python-pygame if you specify with --text.
Note for debian stable user:
if you're using debian stable, you have to manually install ctypes.
python2.4-ctypes is 0.9.5-1 in debian stable,
pypy need version 0.9.9.6 or later:
wget http://nchc.dl.sourceforge.net/sourceforge/ctypes/ctypes-1.0.1.tar.gz
tar zxvf ctypes-1.0.1.tar.gz
cd ctypes-1.0.1
python2.4 setup.py install
* how to translate pypy to c-version pypy with jit *
WARNING: YOU AT LEAST NEED a 512MB RAM box...
I'll recommend 1GB RAM box.
since this will generate a 700mb python process
( 704m 693m 5872 R 99.9 78.3 53:14.25 python2.4,
I build this on 3.2GHZCPU+1GB ram debian stable box)
I first translate pypy in a 512MB RAM gentoo box,
after 3 days memory swapping I gave up.
wget http://codespeak.net/download/pypy/pypy-1.0.0.tar.bz2
#or svn co http://codespeak.net/svn/pypy/dist pypy-dist
tar jxvf pypy-1.0.0.tar.bz2
cd pypy-1.0.0/pypy/translator/goal/
python2.4 translate.py --batch --text --jit targetpypystandalone
and wait 2 hours (if you have 1gb ram)
* woot! pypy-c !
let's check this:
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# ls -lh pypy-c
-rwxr-xr-x 1 root root 9.2M Apr 3 16:22 pypy-c
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# ldd pypy-c
linux-gate.so.1 => (0xffffe000)
libgc.so.1 => /usr/lib/libgc.so.1 (0x4001e000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0x4004f000)
libpthread.so.0 => /lib/tls/i686/cmov/libpthread.so.0 (0x40074000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0x40086000)
libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0x401b7000)
/lib/ld-linux.so.2 (0x40000000)
* The benchmark part
1. startup time is great
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time ./pypy-c -c "print 'hello world!' "
hello world!
real 0m0.006s
user 0m0.003s
sys 0m0.003s
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time python -c "print 'hello world!' "
hello world!
real 0m0.009s
user 0m0.005s
sys 0m0.005s
2. jit speed seems promising.
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time ./pypy-c demo/jit/f1.py > /dev/null 2>&1
real 0m0.449s
user 0m0.442s
sys 0m0.007s
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time python demo/jit/f1.py > /dev/null
real 0m5.347s
user 0m5.343s
sys 0m0.004s
however current JIT not faster than psyco.full():
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time python demo/jit/f1-psyco.py > /dev/null
real 0m0.048s
user 0m0.046s
sys 0m0.002s
3. it's a bit slow in a real test in this stage.
I took the nbody test in "Computer Language Shootout",
http://shootout.alioth.debian.org/gp4/benchmark.php?test=nbody&lang=python&id=0
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time python nbody.py 20000
-0.169075164
-0.169089263
real 0m1.729s
user 0m1.724s
sys 0m0.005s
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time ./pypy-c nbody.py 20000
-0.169075164
-0.169089263
real 0m13.542s
user 0m13.539s
sys 0m0.003s
pypy-c without jit almost 8 times slower :(
and, with the current 1.0 alpha stage JIT, the performance isn't any better.
(since nbody.py use lots of floating arithmetic)
I add these in nbody.py:
import pypyjit
pypyjit.enable(advance.func_code)
pypyjit.enable(energy.func_code)
pypyjit.enable(offset_momentum.func_code)
pypy:/home/tim/pypy-1.0.0/pypy/translator/goal# time ./pypy-c nbody.py 20000 > /dev/null 2>&1
real 0m19.550s
user 0m19.531s
sys 0m0.019s
* conclusion:
1. I don't think pypy 1.0 is ready for production. At least not in my project.
So don't try to replace CPython via pypy at this stage.
(but maybe you have a good reason)
2. pypy 1.0 is not faster than CPython at this stage. Actually, much slower.
(JIT looks promising, however it's still in alpha stage.)
3. pypy really need a 2.0 release. (A joe average user branch)
It looks good,
since it wanna try to do something really different,
but not good enough yet.
we need more.
4. my benchmarking is so naive here, so if you don't like it,
you should do it your own self.
5. despite these, good work.
Thanks the effort from pypy team. we really really need more.
沒有留言:
張貼留言