Newsgroups: comp.lang.java,comp.lang.lisp,comp.lang.lisp.x,comp.lang.perl.misc,comp.lang.python,comp.lang.scheme,comp.lang.scheme.c,comp.lang.tcl
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!newsfeed.internetmci.com!mr.net!news.mr.net!timbuk.cray.com!driftwood.cray.com!roehrich
From: roehrich@cray.com (Dean Roehrich)
Subject: Re: A language extensibility benchmark
Message-ID: <1996Jan31.122912.6567@driftwood.cray.com>
Lines: 128
Nntp-Posting-Host: poplar501
Organization: Cray Research, Inc.
References: <DLuKxo.DnE@world.std.com> <4ejcf0$52d@nntpa.cb.att.com>
Distribution: inet
Date: 31 Jan 96 12:29:12 CST
Xref: glinda.oz.cs.cmu.edu comp.lang.java:20342 comp.lang.lisp:20651 comp.lang.lisp.x:1714 comp.lang.perl.misc:19183 comp.lang.python:8367 comp.lang.scheme:14947 comp.lang.scheme.c:730 comp.lang.tcl:41942

In article <4ejcf0$52d@nntpa.cb.att.com>,
Aaron Watters <arw@quarto.info.att.com> wrote:
>Hi.  This thread is a great idea, and by the way I've looked
>at siod and am very impressed by it.  I recommend it along with
>python.  Here is a python code analogue, It's probably not as compact
>as it could be, and a lot of the C code space is error checking,
>which apparently is more streamlined in siod.

I guess I didn't understand the purpose of soid.  Your python example didn't
need it.  My Perl example doesn't need it.  Maybe you and I missed the point
of why it was used in the original benchmark?

Here's my attempt at the benchmark.  The handholding offered by Perl's h2xs,
xsubpp, and MakeMaker utilities (and Python's MM-related PyMaker, I'm sure)
makes some of the benchmark steps nearly non-ops, I think.

Dean
roehrich@cray.com

------

/*

The benchmark steps:
The exersize is to present a complete solution for the following:
 [1] the makefile section required.
 [2] the interpreted code needed to load and test the extension.
 [3] source code for bootstrapping the extension.
 [4] source code to compute fib(n) using simple recursion.
 [5] source code to compute a string_toupper(s)
 [6] source code to compute a double_array_rms(a)

The original benchmark was heavily skewed toward the lisp community, so
you'll have to forgive me for deviating from it and writing C code as if it
were...well, C code.  I may not have made a faithful translation of the lisp
and lispy-C stuff--I had to make some guesses about lisp and about the
lisp-to-C API.  Unless you're familiar with Perl's perlxs and perlguts
manpages you'll probably have to make similar guesses about the Perl-to-C
API.  Serves you right :)

The original benchmark used an external lisp library for some array
manipulations that I may not fully understand.  Perl doesn't need help with
arrays, so the lisp library is not included and step [1] is basically a
null-op.

*/

#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <math.h>
#ifdef __cplusplus
}
#endif

/* [1] not needed--automated */

/* [2] load and test 

#!/tmp/perl5
use Siodx;
print Siodx::fib(20), "\n";
print Siodx::string_toupper("fooBar"), "\n";
$a = bless [1.0, -2.0, 3.0], AVPtr;
print Siodx::double_array_rms($a), "\n";

*/

/* [3] not needed--automated */

/* [4]  */

static int
fib( int n )
{
	if( n == 0 || n == 1 )
		return( n );
	return( fib( n - 1 ) + fib( n - 2 ) );
}

MODULE = Siodx		PACKAGE = Siodx

# [4], continued

int
fib(n)
	int n

# [5]

char *
string_toupper(s)
	char *s
    PREINIT:
	int j;
    CODE:
	for( j = 0; j < (int)strlen(s); ++j )
		s[j] = toupper(s[j]);
	RETVAL = s;
    OUTPUT:
	RETVAL

# [6]

double
double_array_rms(av)
	AV *av
    PREINIT:
	long j = 0;
	double r = 0.0;
	int len;
	SV **sv;
	double d;
    CODE:
	for( len = av_len(av); j <= len; ++j ){
		sv = av_fetch( av, j, 0 );
		if( sv != NULL ){
			d = SvNV( *sv );
			r += d * d;
		}
	}
	RETVAL = sqrt( r / len );
    OUTPUT:
	RETVAL

