🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #4298

Re: Relative Speed of Perl vs. Tcl vs. C

#4298
From: Matthias Neeracher
Date: Wed, 17 Jan 1996 10:03
81 lines
4326 bytes
[Followups redirected to comp.lang.misc only]
In article <4dhuoj$cbe@shellx.best.com> yogi@shellx.best.com (Yogi) writes:
> I don't want to start a religeous war, and YES, I did read the FAQ's,
> and did not find any info on relative speed of comparing C vs Perl vs Tcl
> vs Java in a very general sort of fashion.

There is a recent posting in comp.lang.java attempting such a comparison.

> I'm very interested in the uses of Tcl and Perl, with regard to Tk and 
> other GUI toolkits (what other's are there?)

By now, almost everybody working with the two languages, seems to be committed
to Tk.

> Can't seem to find any info on statements I have read that seem to conflict:

> Somewhere I have read that Perl coded grep runs as fast or faster than C
> coded grep in Unix. (Larry Wall wrote this, correct me if I'm wrong.)

Possible. grep is almost built into perl.

> And in a CGI-web book I read that Perl is an interpreted language that runs
> 10 times slower than C.

According to Tom Christiansen, a typical factor is on the order of "e", i.e.,
2.7.

> But Perl is compiled, right?

Precompiled, I'd say. I wouldn't call a language "compiled" unless there exists
a mechanism for storing compiled programs in non-source form. A compiler is in
development, though. 

> So how is that different than say, the Tcl interpreter?

Perl and Tcl are almost on the two extreme sides of interpreter
technology. Perl precompiles into an internal parse tree, while Tcl is pure
sring substitution. As an example, compare:

Perl:                                Tcl:
for ($i = 0; $i<100; $i++) {         for {set i 0} {$i<100} {incr i} {
 for ($j = 0; $j=100; $j++) {         for {set j 0} {$j<100} {incr j} {
  for ($k = 0; $k<100; $k++) {         for {set k 0} {$k<100} {incr k} {
   print $i, " ", $j, " ", $k, "\n";    puts "$i $j $k\n";
  }                                    }
 }                                    }
}                                    }

Syntactically, the two examples are very similar. But while the Perl lexical
analyzer makes a single pass over the text of the innermost loop, the Tcl
lexical analyzer makes MORE THAN A MILLION passes over the text.

This does not mean, though, that Tcl is bad. In fact, I find it more than fast
enough for the work I do in it.

> So what's the real answer, or are both statements true somehow? I know that
> Perl can run faster or slower depending on how you code it, (C too) and so I
> guess you would have to find the fastest C code for a particular function and
> similar fastest Perl code (or Tcl) and compare THOSE programs to get a
> definative answer.

One important point to make here is that for text processing problems, it is
much easier writing a close to optimal Perl solution that a close to optimal
C solution and therefore, the Perl solution is often faster although it is
easily proven that a C solution that is at leats as fats must exist.

> And then, what about the speed of Java in comparison to the other 3?

Java proponents will tell you that this doesn't matter because Java has "won"
already. Java detractors will tell you that your question is pointless as there
are not a single release quality implementation of Java in existence as of now.

Matthias

-----
Matthias Neeracher <neeri@iis.ee.ethz.ch> http://err.ethz.ch/members/neeri.html
  "We have built a lot of security directly into Java to make it virus-proof.
   And people's concerns about security on the Net tend to be based on age.
   You talk to people in their twenties and they are much less concerned about
   it than older generations. Pretty soon it won't worry them at all."'
                                -- Scott McNealy, _Sunday Times_ 19Nov95
Technical Details
Message-ID: <NEERI.96Jan17110320@yggdrasil.ethz.ch>
Path: arc1-ca.pugleaf.net!129.132.1.13!neeri
References: <4dhuoj$cbe@shellx.best.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!129.132.1.13!neeri
From: neeri@iis.ee.ethz.ch (Matthias Neeracher)
Newsgroups: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
Subject: Re: Relative Speed of Perl vs. Tcl vs. C
Followup-To: comp.lang.misc
Date: 17 Jan 1996 10:03:20 GMT
Organization: Integrated Systems Laboratory, ETH, Zurich
Message-ID: <NEERI.96Jan17110320@yggdrasil.ethz.ch>
References: <4dhuoj$cbe@shellx.best.com>
NNTP-Posting-Host: yggdrasil.ethz.ch
In-reply-to: yogi@shellx.best.com's message of 16 Jan 1996 20:42:59 -0800