Article View: comp.lang.prolog
Article #895Re: Proof that Prolog can be faster than C
From: Dan KoGai
Date: Fri, 15 Jun 1990 20:52
Date: Fri, 15 Jun 1990 20:52
41 lines
1755 bytes
1755 bytes
In article <36986@ucbvax.BERKELEY.EDU> vanroy@pisces.uucp () writes:
> [benchmark omitted]
>
>/* C version of tak benchmark */
>
>#include <stdio.h>
>
>int tak(x,y,z)
>int x, y, z;
>{
> int a1, a2, a3;
> if (x <= y) return z;
> a1 = tak(x-1,y,z);
> a2 = tak(y-1,z,x);
> a3 = tak(z-1,x,y);
> return tak(a1,a2,a3);
>}
But this C code is hardly optimum. 1st of all you don't need
a1, a2, a3 to waste space and time. try the following.
int tak(int x, int y, int z)
{
return (x <= y) ? z : tak(tak(--x, y, z),tak(--y, z, x),tak(--z, x, y))
}
> [Prolog version omitted]
And it's also unfair to compare 2 versions without posting the
assembly codes both versions made. Both C and Prolog allow programmers
to write various codes doing the same thing.
----------------
____ __ __ + Dan The Walking C Obfscunator
||__||__| + E-mail: dankg@ocf.berkeley.edu
____| ______ + Voice: +1 415-549-6111
| |__|__| + USnail: 1730 Laloma Berkeley, CA 94709 U.S.A
|___ |__|__| +
|____|____ + "Unix is not insecure. It's people who are"
\_| | + "Unix doesn't have pain. It's people who do"
Technical Details
Message-ID:
<1990Jun15.205242.16314@agate.berkeley.edu>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!apple!bionet!agate!volcano.Berkeley.EDU!dankgReferences:
<36986@ucbvax.BERKELEY.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!apple!bionet!agate!volcano.Berkeley.EDU!dankg From: dankg@volcano.Berkeley.EDU (Dan KoGai) Newsgroups: comp.lang.prolog,comp.lang.c Subject: Re: Proof that Prolog can be faster than C Summary: But you can optimize C code further! Keywords: Prolog, tak Message-ID: <1990Jun15.205242.16314@agate.berkeley.edu> Date: 15 Jun 90 20:52:42 GMT References: <36986@ucbvax.BERKELEY.EDU> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: dankg@volcano.Berkeley.EDU (Dan KoGai) Organization: ucb Lines: 41