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

Tom Christiansen (tchrist@mox.perl.com)
29 Sep 1994 22:27:11 GMT

:-> In comp.lang.tcl, guido@cwi.nl (Guido van Rossum) writes:
: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?

Well, the question is whether the appending is

array = element array
or
array = array element

It turns out that you guys have all been testing perl's unshift.
Its unshift is highly inefficient. If you want to append to a list,
not prepend to it, then you use

push(@array, $element;

yeilding:

array = array element

saemantics instead.

The unshift version on my architecture runs this fast:
10.300u 0.190s 0:10.80

But the push version runs this fast:
0.840u 0.210s 0:01.01

That's a pretty dramatic speedup. Now, if you use version 5.0 and
ask that arithmetic be done in integer instead of floating point
by adding
use integer;
at the top of your program, then you get this performance:

0.690u 0.190s 0:00.85

Now, I agree that an order of magnitude difference between appending and
prepending is a bad idea, but unshift isn't a good way of measuring perl's
performance. My integer push version is 15 times faster than the floating
unshift version, which means that I may be able to infer that the perl
version is actually 3 times faster than the python version. I'd hate to
even compare it against tcl, which has a different mission and thus should
perhaps be excused from having a speed in this benchmark which seems to
vary from merely glacial to that of continental drift. :-)

--tom

-- 
"Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in."
	--Larry Wall in <1994Jul21.173737.16853@netlabs.com>

Tom Christiansen Perl Consultant, Gamer, Hiker tchrist@mox.perl.com