Long ago I compared the speed of a Python version of fac(n) with a
figures given by Ousterhout for an early version of Tcl. On the only
machine to which both I and Ousterhout had access (a DECstation 3100)
execution of the Python version was about 3 times as fast. The Python
function was this:
if n == 1: return 1
else: return n * fac(n-1)
and it took 1.3 msec/call; the equivalent Tcl (don't have the source
handy) took 3.6 msec/call.
I expect that a fair comparison of the speeds of Python and Tcl will
be hard: both have the property that complex operations (such as
regular expression matches) will run at the same speed as C (because
they are implemented in C), while simple things like "i = i+1" takes
forever compared to C.
Given what I know of the Tcl implementation, I expect that operations
using complex data will be slower in Tcl because they are represented
as strings that must be packed and unpacked (this is even true for
numbers). Tcl also has to do more work decoding the commands because
they are parsed on the fly, during execution, while Python represents
them in binary.
However, Python programs take more time up front because the code is
parsed and `compiled' before it is executed. Fortunately, the
compiled representation of a module is cached (for every module
"foo.py" there is a cache file "foo.pyc", saving a lot of parse time).
Also, Tcl uses tricks like allocating small buffers on the stack
instead of on the heap to reduce the number of malloc() and free()
calls, while Python allocates all objects except integers on the heap.
I can imagine that this might make a null routine call in Tcl faster
than the same in Python; however the figures of the 'fac' example
above (which is function call intensive) seem to imply that Python is
--Guido van Rossum, CWI, Amsterdam <firstname.lastname@example.org>
"You're so *digital*, girl!" -- Neneh Cherry