Latest blog posts

Testing basic datastructures in various programming languages »

proycon | November 20, 2009 | Absolute URL to this post Link

Have you ever wondered how your favourite programming language compares to others in terms of speed? How does for example Python compare to Ruby, PHP, Java or Perl? And how do all these scripting languages compare to actual compiled C++ code?

In most programming tasks, a central role is played by data structures such as arrays/lists, and hashes/dictionaries. I was curious how the performance of precisely such data structures differs across different languages. To test this, I wrote a series of basic data tests in all of the aforementioned programming languages, and I timed the execution of each test.

Besides a benchmark study, it was also a nice exercise to write essentially the same script in many different languages.

I will summarize some of the results of my experiments. I ran all tests 10 times on a Intel Core 2 Duo (Macbook Pro 5,3), running a 64-bit Ubuntu Linux 9.10. All times are in seconds and of course machine specific. C++ code was compiled with gcc 4.4.1, and for Java the Sun JDK 1.6.0 was used.

You can run all tests yourself, download the scripts and sources, inspecting the sources may also provide valuable insight in seeing how the tasks are implemented in the various languages.

Note that this is something I fairly quickly set up, so it may be that a few tests can be implemented more efficiently.

Test 1a/2a: Creating a new list of many integers:

Instantiating an array/list of two million integers (0 to 1999999). Note that all types except the C array are dynamically extendable.

C Array* 0.014
C++ STL Vector 0.032
Ruby 1.9 Array 0.217
Perl Array 0.307
Python 3 List 0.392
Python 2.6 List 0.441
Java Vector 0.61
PHP5 Array 0.795
Ruby 1.8 Array 1.142

Test 2c: Test if a value is in the list

Locating a value in the list, the value will be found half-way

C++ STL Vector 0.0
Java Vector 0.02
Python 2.6 List 0.02
Ruby 1.9 Array 0.04
Ruby 1.8 Array 0.051
Python 3 Array 0.07
PHP5 Array 0.07
Perl 5.10 Array (using grep) 1.458

Test 2e: Sorting a list

A sort is done on a list of two million random integers.

Ruby 1.8 Array 0.33
Ruby 1.9 Array 0.363
STL sort on C Array 0.423
C++ STL Vector 0.798
Python 2.6 List 1.47
Python 3 List 1.617
Java Vector 1.692
Perl Array 4.475
PHP5 Array 6.819

Test 2f: Polling all elements in a list

The value of each list item is retrieved during iteration over all items.

C++ STL Vector 0.007
Ruby 1.9 Array 0.132
Java Vector 0.281
Perl 5.10 Array 0.286
Ruby 1.8 Array 0.514
Python 3 List 0.523
Python 2.6 List 0.524
PHP5 Array 0.746

Test 2g: Setting all elements in a list

Set all items in a list to zero

C Array 0.01
C++ STL Vector 0.01
Java Vector 0.093
Ruby 1.9 Array 0.18
Python 3 List 0.529
Perl Array 0.537
Python 2.6 List 0.552
PHP5 Array 0.763
Ruby 1.8 Array 0.969

Test 2h: Inserting 10 elements

Ten insertions in the middle of an array of two million.

Ruby 1.8 Array 0.033
C++ STL Vector 0.035
Ruby 1.9 Array 0.044
Python 3 List 0.073
Python 2.6 List 0.078
Java Vector 0.079
PHP5 Array 13.204

Test 2i: Delete 10 elements

Ten deletions in the middle of an array of two million.

C++ STL Vector 0.03
Ruby 1.8 Array 0.03
Ruby 1.9 Array 0.034
Python 3 List 0.071
Java Vector 0.073
Python 2.6 List 0.085

Test 3a: Creating map of two million integers (key==value)

C++ TR1 Unordered Map 0.495
Python 3 Dictionary (unordered) 0.499
Python 2.6 Dictionary (unordered) 0.576
Ruby 1.9 Hash (unordered) 0.7
Ruby 1.8 Hash (unordered) 1.537
C++ STL Map (ordered) 1.791
Perl Hash 2.235
Java HashMap 3.249

Test 3b: Check if a key exists in map

Check if a key exists in the map: Less than 0.001 second for all languages

Test 3e/3f: Polling all elements in map

Retrieving the values of all elements

C++ TR1 Unordered Map (no iterator) 0.094
Java HashMap (using iterator) 0.099
Java HashMap (without iterator) 0.231
Python 3 Dictionary (items() method) 0.265
Python 2.6 Dictionary (iteritems() method) 0.27
C++ STL Map (ordered, no iterator) 1.044
Perl Hash 2.84
Ruby 1.9 Hash (each() method) 7.671
Python 2.6 Dictionary (items() method) 7.93
Ruby 1.8 Hash (each() method) 12.117

Test 3h: Setting all elements in map

Setting all elements in the map to zero

C++ TR1 Unordered Map 0.097
Java HashMap 0.306
Python 3 Dictionary 0.335
Ruby 1.9 Hash 0.383
Python 2.6 Dictionary 0.404
C++ STL Map (ordered) 1.055
Ruby 1.8 Hash 1.247
Perl 5.10 Hash 6.049
Comments | Post a comment Post a comment | Share this Share this | Tags :

Python completion plugin for gedit »

proycon | August 17, 2009 | Absolute URL to this post Link

I made some small improvements in an existing gedit plugin for python code completion. The original post of the main author can be found here. My contribution consists of a few lines of code that enables the user to type unhindered by the window that pops up with suggestions. The window will automatically highlight methods and properties as you type along in the main window, and you can use the TAB key for autocompletion. My aim was to make the popup less obstructive and more transparent.

Download the modified code from GitHub.

Comments | Post a comment Post a comment | Share this Share this | Tags :

Launched new homepage! »

proycon | August 17, 2009 | Absolute URL to this post Link

I have launched a completely reworked version of my homepage. As you can see it features a fresh new layout and updated content. Another notable addition is a new multilingual video in my languages section.

The majority of the changes is technical in nature and can be found "under the hood" of the site, which is now written written in Python and Django, and on top of that using FeinCMS and django-diario.

Comments | Post a comment Post a comment | Share this Share this | Tags :

New website launched! Proycon's Language Technology »

proycon | October 19, 2008 | Absolute URL to this post Link

I launched a new website: Proycon's Language Technology (click to visit)! Whilst the website you are on now is my personal website, this new site is a more professional website where you can read about Language Technology and find software I wrote.
Comments | Post a comment Post a comment | Share this Share this | Tags :

Social Networks »

proycon | September 6, 2008 | Absolute URL to this post Link

Quite a while ago already, I made an overview of the social networking sites where I have a profile. You can take a peek if you want to see if I also happen to be on your favourite social networking site: View my networks

New UniLang site launched! »

proycon | September 6, 2008 | Absolute URL to this post Link

I forgot to write up on this, but on the 24th of July, the new UniLang site has been launched! After a lot of hard work and a sudden harddisk crash, the new UniLang site is now finally available and everything has been completely renewed! You can visit UniLang, an online community for language learning, at www.unilang.org.
unilang logo
Comments | Post a comment Post a comment | Share this Share this | Tags :

Met Linux VPN Verbinding maken met de Universiteit van Tilburg »

proycon | September 6, 2008 | Absolute URL to this post Link

Ik heb de Cisco VPN instructies die ik al eerder schreef voor de Universiteit Utrecht nu ook aangepast aan de Universiteit van Tilburg. Bovendien is er een nieuwe Cisco VPN client uit die de dingen wat makkelijker maakt (geen patches meer nodig zoals voorheen). Zie hier voor het artikel.

proycon@FaceBook »

proycon | January 11, 2008 | Absolute URL to this post Link

I'm starting to more actively use FaceBook nowadays, FaceBook is quite a nice social networking site. I even wrote a small language application for the platform!

You can add me there, search for me under my real name, as that is the custom on FaceBook.



Maarten van Gompel's Facebook profile
mail iconE-mail: proycon
mailMSN/Live Messenger:proycon
jabberJabber:proycon
googletalkGoogleTalk:proycon
skypeSkype:proycon_linux
yahooYahoo Messenger:proycon
aimAOL Instant Messenger (AIM):proycon