4 notes &
Pystone benchmark on 2.6,2.7,3.2
The new Python 3.2 branch brings one of the largest changes to Python to date. The GIL (Global Interpreter Lock) has been the source of much heart ache for many programmers hoping to write multi-threaded applications in Python.
While the GIL is hated by many, it is unknowingly loved by much more. Correctly leveraging threads is hard and some say impossible. There is a blog post in which an engineer from Sun Microsystems discuses a thread scheduling issue in Solaris.
The GIL prevent most if not all of these problems by locking onto one thread until said thread “gave up” the lock or a certain amount of interpreter instructions “ticks” occurred.
I will get into the new GIL in CPython 3.2 in a later post (I am running a few tests) but here are some pystone benchmarks on all the latest versions of Python.
CPU Info
Processor Name: Intel Core 2 Duo
Processor Speed: 2.53 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 3 MB
Memory: 4 GB
Bus Speed: 1.07 GHz
Python 2.7
BashMe:~ User$ python2.7 -c “from test import pystone;pystone.main()”
Pystone(1.1) time for 50000 passes = 0.737365
This machine benchmarks at 67809 pystones/second
Python 2.6.5
BashMe:~ User$ python2.6 -c “from test import pystone;pystone.main()”
Pystone(1.1) time for 50000 passes = 0.84
This machine benchmarks at 59523.8 pystones/second
Python 3.2 (Beta)
BashMe:~ User$ python3.2 -c “from test import pystone;pystone.main()”
Pystone(1.1) time for 50000 passes = 0.720697
This machine benchmarks at 69377.3 pystones/second
Python 3.2 looks promising coming out just a little faster than Python 2.7. I will be experimenting with the GIL on both 2.7 and 3.2 and will post the results.
P.S Just for fun I am including the results of PyPy and Jython
PyPy 1.4
BashMe:~ User$ pypy -c “from test import pystone;pystone.main()”
Pystone(1.1) time for 50000 passes = 0.256478
This machine benchmarks at 194948 pystones/second
Jython 2.5.1
BashMe:~ User$ jython -c “from test import pystone;pystone.main()”
Pystone(1.1) time for 50000 passes = 2.56169
This machine benchmarks at 19518.3 pystones/second
Update:
We are not doing PyPy justice because only one pass doesn’t leverage the JIT. Here is PyPy running Pystone 10 times in a row.
»» from test import pystone
»» for i in range(10):
…. pystone.main()
….
Pystone(1.1) time for 50000 passes = 0.25995
This machine benchmarks at 192345 pystones/second
Pystone(1.1) time for 50000 passes = 0.08655
This machine benchmarks at 577701 pystones/second
Pystone(1.1) time for 50000 passes = 0.079298
This machine benchmarks at 630533 pystones/second
Pystone(1.1) time for 50000 passes = 0.077387
This machine benchmarks at 646103 pystones/second
Pystone(1.1) time for 50000 passes = 0.079177
This machine benchmarks at 631497 pystones/second
Pystone(1.1) time for 50000 passes = 0.077597
This machine benchmarks at 644355 pystones/second
Pystone(1.1) time for 50000 passes = 0.079026
This machine benchmarks at 632703 pystones/second
Pystone(1.1) time for 50000 passes = 0.077798
This machine benchmarks at 642690 pystones/second
Pystone(1.1) time for 50000 passes = 0.078652
This machine benchmarks at 635712 pystones/second
Pystone(1.1) time for 50000 passes = 0.078287
This machine benchmarks at 638676 pystones/second
The results speak for themselves.