Posts Tagged ‘comparison’

Python 3 is slower than Python 2?

August 15, 2013 2 comments

Recently I was playing with concurrent.futures. Following a comment on reddit, I got to the presentation of David Beazley entitled Understanding the Python GIL.

It’s a very interesting talk and from this I learned that Python 3.2 got a new GIL implementation! Out of curiosity I compared the performance of Python 2.7 and 3.3. The test machine had 4 cores. I made a CPU bound test script with three variations: (1) basic, single-threaded version, (2) using 4 threads, and (3) using 4 processes.

The results were surprising for me because Python 2.7 turned out to be faster!

(Legends: Py2 = Python 2.7.4, Py3 = Python 3.3.1)
Py2: 5.32 sec, Py3: 9.66 sec

Py2: 13.41 sec, Py3: 17.32 sec

Py2: 1.28 sec, Py3: 2.27 sec

You can also try the scripts, they are here.

Categories: python Tags: , , ,