Saturday, April 21, 2007

Benchmarks of different computer programming languages

Here is a bench mark of different programming languages,
http://shootout.alioth.debian.org/gp4/
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=java

For example, a comparison between c (using gcc) and Java (Sun JDK, but just note that some time IBM JDK runs faster than Sun JDK)
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=gcc&lang2=java
C application starts 91 times much faster than Java and take 22 times less memory in recursion.
Of course every one agrees that C is much faster than Java. But what is more important is the analysis of the results.
For example between C and Java, except that Java takes more memory and Start up is very slow, C is just 2 times better than Java.
Hence where memory is more and we won't start the application too often Java is better taking in to account its garbage collection and vast library. So, application servers (J2EE servers) are perfect for Java rather than Desktop application like notepad. Generally you re-start a server once in a month or so (hence start up speed of C 91 times better doesn't really matter here) and servers will have 5 GB RAM and hence whether the application takes 100 MB or 500 MB memory really is not a matter. Cool.

Now lets compare Java and Python
http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang= java&lang2=python
Even though Python is very slow compared to Java (in some case 90 times slower in recursion), it is much better in Memory (almost in every case, it takes less memory some time 10 times) and it starts 7x better than Java. Now you got the idea, Python is better for desktop applications as it takes less memory. Desktop application memory is more important. Image Java application takes around 20 MB, then you can even run 15 Java applications on a 512 MB RAM Desktop (taking into account OS will also take some memory), but Python takes 10 times less memory so you can easily run 150 Python application simultaneously. So, we can safely conclude that Python is very hot for Desktop application (of course C is better than Python, but comparing with the huge standard library Python provides, even bigger and cleaner than Java ;- Memory usage of Python is comparable with C), it is better for Desktop applications than C or Java where memory is more important than fast (yes, imagine a Notepad written in Java than takes 20 MB of memory, 2 minutes to start and then runs as fast as C notepad. Whereas python may take around 1 or 2 MB, takes around 10 secs to load but runs slower than C Notepad. But do the user really able to differentiate a program that take 2 ms or 200 ms, here even though the other program is 100 times faster than C, it doesn't matter in this case, it matters in RDBMS or Search engines Right?).

http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang= python &lang2=perl
Comparing Perl and Python, see that except in one case) both are equally good. So now we should consider only the Language, library, and portability advantages. For some fun we will compare these now.
Python is a very clear Object oriented language, on the other hand Perl supports both OO and Structural programming. Python has a big standard library set than Perl. But developing small proto-type application in Perl is far easier than Python (in Python you need to define a class, methods). So, perl better as a scripting language or cgi programming rather than for developing large scale applications (because for large applications Perl looks cluttered and Python look very organized).

So, which language is better? It depends on the type of application we are developing.

Regards
Suresh

Copyright (c) 2008 - Suresh