Proof that Prolog can be faster than C

Dan KoGai dankg at volcano.Berkeley.EDU
Sat Jun 16 06:52:42 AEST 1990


In article <36986 at ucbvax.BERKELEY.EDU> vanroy at 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 at 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"



More information about the Comp.lang.c mailing list