Python vs. C/C++/Java: quantitative data ?

Magnus Lyckå magnus at trhinkware.se
Thu Feb 21 06:46:18 EST 2002


Eduard Smirnov wrote:

  > I'm writing a diploma paper on the difference between scripting
  > (e.g. in Python or Tcl) and system programming (e.g. in C, C++ or
  > Java), and one of the claims I want to make is that you can often
  > develop applications 10x or more faster in a scripting language.

I wouldn't really say that Python is a scripting language though. The
name scripting language suggests a language suited for small snippets.
Python is as much a general language for large scale software
development as C++ is. But Python is surely a rapid development
language.

Bash, awk, Tcl and Perl are in my opinion scripting languages, but
not Python. (Well, Perl probably has the theoretical requirements for
developing large systems, but it's fairly obscure and bolted on as an
afterthought.)

  > I apologue that more applications can be written or re-written in
  > scripting language faster and with more complex functionality then
  > in system programming language. If you have any experience in
  > writing applications in system programming language (e.g. in C,
  > C++) and re-writing it in scripting language (e.g. Python) or vice
  > versa, please compare your work in both implementations,

Actually, I think many comparisions are made like this, and a problem
is that if you first write in C, and then translate, you are likely to
use your C design for Python, and end up with a program that is almost
as big, but much slower. If you go the other way, there is no way you
can use your Python solution directly, since C can't handle the level
of abstraction, and you will probably get a fairer comparision.

  > describe your work/application's functionality, approximate number
  > of lines and time of development of each implementation, skill's
  > level needed. Any more comments about are welcome.

Personally, my Python applications worked well, thank you, so I
never rewrote them in any other language...

There are some links at
http://www.thinkware.se/cgi-bin/thinki.cgi/PythonQuotes
which might guide you do relevant sources. (Glyph Lefkowitz,
Greg Stein and Eric S. Raymond for instance.)

Also, have a look at
http://wwwipd.ira.uka.de/~prechelt/Biblio/jccpprt_computer2000.pdf
For this experiment, the productivity gain with Python is roughly
factor three, but this is also

There is a comparision at http://www.bagley.org/~doug/shootout/
but it's really just a pointless play. Don't fall for this one.
It has two fundamental flaws: It only uses small programs, so
it doesn't show you anything about how the language scales. If you
believed in that, do all your coding in C and bash. It also ignores
one of greatest assets of Python, its rich standard library.

So instead of writing the "random generator" as

import random
print random.random()

They reinvent the wheel like this:

import sys

IM = 139968
IA = 3877
IC = 29573

LAST = 42
def gen_random(max):
      global LAST
      LAST = (LAST * IA + IC) % IM
      return( (max * LAST) / IM )

def main():
      N = int(sys.argv[1])
      if N < 1:
          N = 1
      gr = gen_random
      for i in xrange(1,N):
          gr(100.0)
      print "%.9f" % gr(100.0)

main()

In other words, many of the programs are about as long
as C programs since they "level the playfield" by not
using the "included batteries". On the other hand Python
always show more CPU and memory usage since it loads the
interpreter and a lot of modules before it runs the those
twenty lines of code. No wonder that C seems slim and fast
there. If we talked about a REAL application, and compared
50 000 lines of C++ with 10 000 lines of Python code, things
would look very different.









More information about the Python-list mailing list