Newsgroups: comp.lang.dylan
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!scramble.lm.com!news.math.psu.edu!news.cac.psu.edu!howland.reston.ans.net!swrinde!newsfeed.internetmci.com!news-feed.iguide.com!news.uoregon.edu!news.hawaii.edu!phinely
From: phinely@Hawaii.Edu (Peter Hinely)
Subject: Dylan vs. C results for simple benchmark
X-Nntp-Posting-Host: uhunix4.its.hawaii.edu
Message-ID: <DrDDv5.HIF@news.hawaii.edu>
Sender: news@news.hawaii.edu
Organization: University of Hawaii
Date: Tue, 14 May 1996 00:40:17 GMT
Lines: 72


Hi folks,

In a fit of boredom, I timed the C and Dylan versions of a simple
recursive algorithm.  The algorithm "computes the number p(n,k) of ways of
writing n as the sum of k positive numbers (irrespective of ordering),
i.e., the number of k-way partitions of n." 


The following times are for PPC-native executables on a PowerMac 7100/80:

Compiler                                             Running Time
--------                                             ------------
Metrowerks CodeWarrior 8 (full optimization)           5 seconds
Apple Dylan TR (patch not applied)     		      15 seconds


The relevant excerpts of code:

Dylan version
-------------
define method main (argv0, #rest noise)
	for(i from 1 to 10)
		p(100, i);
	end for;
end method main;


define method p(n :: <integer>, k :: <integer>) 
                    => result :: <integer>;
	if(k = 1 | k = n)
		1;
	elseif(k < 1 | k > n)
		0;
	else
		p(n - 1, k - 1) + p(n - k, k);
	end if;
end method p;



C version
---------
#include <stdio.h>

int p(int n, int k);


void main(void)
{
  int i;

  for (i = 1; i <= 10; i++)
    p(100, i);
}


int p(int n, int k)
{
  if (k == 1 || k == n)
  	return 1;
  else
  {
    if (k < 1 || k > n) 
      return 0;
    else return p(n-1, k-1) + p(n-k, k);
  }
}


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

