🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #909

Re: Bogus! (was Re: Proof that Prolog can be faster than C)

#909
From: Peter Van Roy
Date: Wed, 13 Jun 1990 22:57
72 lines
2920 bytes
In article <1990Jun12.212525.25551@iwarp.intel.com> merlyn@iwarp.intel.com (Randal Schwartz) writes:
>
>Bogus.
>
>Comparing apples and oranges dude.
>
>The prolog version most likely saves results from tak(a,b,c) so that
>they can do a quick lookup the next time around.  I jimmied up one
>in perl that does the same thing...
>
>Just another Perl hacker,
>/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\

Please do not jump to conclusions.  The Prolog implementation does *NOT* save
intermediate results from tak(a,b,c).  It is doing *ALL* recursive calls.
(I wish the compiler were intelligent enough to do what you say it does :-).
The speed is due to straightforward compiler optimization.  By the way, the
behavior of tak is not an isolated case.  For example (times in user seconds,
as before):

Benchmark       Prolog          C (no opt.)     C (opt. 4)

fib(30)         1.5             2.0             1.6

This program is doing all recursive calls too.

Because older implementations of Prolog have been relatively slow, it is
sometimes believed that this is inherent in the language.  The purpose of
my original message was to dispel that notion by providing measurements of
an optimizing Prolog compiler.

Recent work in Prolog implementation has significantly improved performance.
You might want to look at "Fast Prolog with an Extended General Purpose
Architecture" by Bruce Holmer et al in the 17th International Symposium on
Computer Architecture and "LIPS on a MIPS: Results from a Prolog Compiler for
a RISC" by Andrew Taylor in the 1990 International Conference on Logic
Programming.

Sincerely,
  Peter Van Roy

-------------------------------------------------------------------------------

/* C version of fib benchmark */

#include <stdio.h>

int fib(x)
int x;
{
  if (x <= 1) return 1;
  return (fib(x-1)+fib(x-2));
}

main()
{
  printf("%d\n", fib(30));
}

-------------------------------------------------------------------------------

/* Prolog version of fib benchmark */

main :- fib(30,N), write(N), nl.

fib(N,F) :- N =< 1, F = 1.
fib(N,F) :- N > 1,
        N1 is N - 1, fib(N1,F1),
        N2 is N - 2, fib(N2,F2),
        F is F1 + F2.

-------------------------------------------------------------------------------
Technical Details
Message-ID: <37011@ucbvax.BERKELEY.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!pisces!vanroy
References: <36986@ucbvax.BERKELEY.EDU> <1990Jun12.212525.25551@iwarp.intel.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!pisces!vanroy
From: vanroy@pisces (Peter Van Roy)
Newsgroups: comp.lang.prolog
Subject: Re: Bogus! (was Re: Proof that Prolog can be faster than C)
Message-ID: <37011@ucbvax.BERKELEY.EDU>
Date: 13 Jun 90 22:57:10 GMT
References: <36986@ucbvax.BERKELEY.EDU> <1990Jun12.212525.25551@iwarp.intel.com>
Sender: usenet@ucbvax.BERKELEY.EDU
Reply-To: vanroy@pisces (Peter Van Roy)
Organization: University of California at Berkeley
Lines: 72