Perl versus Python

I love to program and have switched programming languages many times over the years. I mainly program in scripting languages these days as most of the programs that I want to do start out simply processing some data and then grow. I am always in amazement how long my programs are still running.

Anyway. I have done a lot of Perl programming, but for the past few years, I switched to Python. I find Python a much cleaner language with a better integrated object oriented space over Perl.

And, until recently, I was very happy with Python. I was recently running a multi-threaded program and wondering why it would not take advantage of all my cores on my i7 Macbook Pro. After doing some research, I found out that the issue was with Python’s Global Interpreter Lock (GIL). There are a lot of discussions on the GIL, but the bottom line is that Python is not able to take advantage of all your cores if you are doing a multi-threaded program.

So, what did I do? I wrote two similar programs; one in Python and one in Perl. These programs just spawned multiple threads and did some multiplication in a very large loop and it was very interesting what I found out. With one thread, Perl was about 8 seconds and Python was about 9 seconds. With two threads, Perl was still about 8 seconds and Python was about 30 seconds. For seven threads (one less than the number of cores on my system), Perl was about 11 seconds. It took about 20 threads in Perl to get to 30 seconds.

I am not sure what I will be writing my next program in, but it will clearly depend upon what I need the program to do.

Leave a Reply

Your email address will not be published. Required fields are marked *