Home > python > Python 3 is slower than Python 2?

Python 3 is slower than Python 2?

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: , , ,
  1. akismetuser34715126
    November 17, 2013 at 16:47

    Any idea why Py3 is so much slower than Py2? In the other hand additional time caused by threads is smaller in Py3…

    • ojagodzinski
      November 17, 2013 at 16:54

      But again… CPU bound task should be way slower with threads on Py3 because of GIL timeout and many context switching… It don’t get it.

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: