Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!pipex!uknet!newsfeed.ed.ac.uk!hwcee!andrew
From: andrew@cee.hw.ac.uk (Andrew Dinn)
Subject: Re: speed of prolog
Message-ID: <D90wt4.32n@cee.hw.ac.uk>
Sender: news@cee.hw.ac.uk (News Administrator)
Organization: Dept of Computing and Electrical Engineering, Heriot-Watt University
X-Newsreader: TIN [version 1.2 PL2]
References: <3pam2e$9jh@chuangtsu.acns.carleton.edu> <3pptgj$6do@percy.cs.bham.ac.uk>
Date: Tue, 23 May 1995 08:55:52 GMT
Lines: 53

James A Hammerton (J.A.Hammerton@cs.bham.ac.uk) wrote:
: nelsonb@mathcs.carleton.edu wrote:

: : I have heard that prolog is fast.  Is this true?  If it is, why?  Thanks.

: I don't know where you heard that from. Prolog is not going to be as
: fast as say C or C++, because...

Oh dear. The answer here is almost as irrelevant as the question. A
language can hardly be described as slow or fast per se. Firstly, it
depends what you try to do with it. So *programs* are fast or slow,
not languages. Secondly, even if one resorts to picking a particular
task and coding it in say Prolog and C++ that might tell you something
about the job in hand and might indicate some likely corollaries when
it comes to coding other (similar) tasks but it might also just tell you
something about the compiler or operating system you are using or even
your ability as a coder in these two languages. So much depends.

The second poster is right that the interpretation of Prolog affects
performance but whether this is for the better or worse is not clear
cut. Compilation to native code is an alternative but this often leads
to code bloat and massive swapping problems. Mind you, code bloat in
C++ systems also affects performance. Smalltalk-80 uses on the fly
compilation to native code to very great effect, almost halving
execution time on most programs. This is not a simple issue.

Ditto for garbage collection. Most C and C++ programs use malloc and
free to do garbage collection which may involve operating system calls
to allocate virtual memory and are often very badly coded. The GNU
malloc library is a lot better than most vendors libraries, but then
it was written by people who know about garbage collection. Top
quality garbage collectors can make code which *has to* use dynamic
memory allocation far more efficient in Prolog than in C++ (good
garbage collectors only collect valid data which can give constant
overheads, C++ has to explicitly free all rubbish which gives
overheads proportional to the amount of memory allocated).

Undoubtedly, for many tasks a Prolog program, even when coded by an
expert, cannot do the same job as fast as a C++ program coded by an
expert. But for some tasks the converse is the case. Take away the
qualification that the programmer is an expert and the answer is far
less clear cut. And to add insult to injury, if you are not an expert
then you probably ought to either become one, find one to do the job
for you or stop worrying about raw speed and start worrying about
other more important properties which your programs need to have such
as readability, maintainbability, reusability, testability etc. Speed
is the cherry. Learn to bake the cake first.


Andrew Dinn
-----------
O alter Duft aus Maerchenzeit / Berauschest wieder meine Sinne
Ein naerrisch Heer aus Schelmerein / Durchschwirrt die leichte Luft
