Re: Tcl/Lisp/Python: A "User" point of view

Guido van Rossum (Guido.van.Rossum@cwi.nl)
Thu, 29 Sep 1994 10:41:33 GMT

mdimeo@brooktree.com (Matt DiMeo) writes:
>The users will care about O(1) vs. O(n) as soon as they notice how long it
>takes for tcl to build up a ten thousand element list.

>tst.tcl------------------
>set l ""
>for { set i 0 } { $i < 10000 } { incr i } {
> lvarpush l $i
>}
>-------------------------

>tst.perl-----------------
>for ($i = 0 ; $i < 10000 ; $i++) {
> unshift(@f, $i) ;
>}
>-------------------------

>{/home/mdimeo}% /bin/time /cad/bin/perl tst.perl
> 4.8 real 4.6 user 0.0 sys
>{/home/mdimeo}% /bin/time tcl tst.tcl
>^CCommand terminated abnormally.
> 334.2 real 326.7 user 0.2 sys

Since this was cross-posted to comnp.lang.python, here are the results
of comparing Perl and Python. I print the Perl numbers too since the
CPU was unspecified.

& time perl tst.pl

real 5.94
user 5.74
sys 0.09

& time python tst.py

real 1.35
user 1.12
sys 0.08

& cat tst.py
l = []
for i in range(10000):
l.append(i)

& cat tst.pl
for ($i = 0 ; $i < 10000 ; $i++) {
unshift(@f, $i) ;
}

&

Should I say more?

One note on the Python program -- I could've cheated and simply used
l = range(10000)
but that would've moved the entire loop into C, while what's really at
stake here is 10000 calls to the internal "append to list" call.

BTW this is not a formal benchmark by any means! I'm sure that there
are lots of things that Perl does faster -- and lots of things where
Python wins. They are meant for different purposes.

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>