[Shootout-list] Directions of various benchmarks

skaller skaller@users.sourceforge.net
18 May 2005 20:52:26 +1000


On Wed, 2005-05-18 at 16:13, Jos=C3=A9 Bollo wrote:
> Le mercredi 18 Mai 2005 07:53, Bengt Kleberg a =C3=A9crit :
> > skaller wrote:
> > ...deleted
> >
> > > Are we measuring the cost of interfacing to an
> > > external library .. and if so how can we do that
> > > when external libraries are excluded ..? <g>
> >
> > would it be a good idea to have a specific test for this purpouse?
> > a ''foreign function interface'' test.
> > and disallow such use in other tests?
>=20
> EIFFEL will win for interfacing any C / C++ / JAVA external libraries.

Then it will be equal to Felix on simple tests -- and I curious what the
interface looks like, can you show me?

> And forget such kind of test for many languages like Tcl / Java ...
>=20
> Let show an example:
>=20
> 	one write a C library and publish the interface:
> 		float compute_it_fast(float x, float y)

Felix, assuming the C code is included:

	fun compute_it_fast: float * float -> float;

if the header lives in file 'fast.h' then:

 	fun compute_it_fast : float * float -> float
		requires header '#include "fast.h"'
	;

which has the advantage of only including 'fast.h' if the
function compute_it_fast is actually used. This leaves the problem
of linking the code however this does not:

	fun compute_it_fast: float * float -> float
		requires body """
		float compute_it_fast (double x, double y) {
			return x + y;
		}
		"""
	;

which will compile the C from source along with the Felix that
uses it (if, and only if, it is actually used .. ) and is therefore
a complete 'single file' solution.

Show me the Eiffel?=20

Now show me the Eiffel where the argument is a struct:

	struct C F2 { float x; float y; }

Here is the Felix:

	cstruct F2 { x: float; y: float; }
	fun compute_it_fast: F2 -> float;

[again with the option of making the inclusion of the header
file conditional on actually using the type and/or function]

So I'm claiming 1 LOC for problem 1, and 2 LOC for problem 2
and NO language that can't read C headers can possibly beat that.

The final challenge is much harder: a Gtk GUI function with
a callback/client data argument .. Felix has a tool 'flxcc'
that will detect this automatically and generate the required
bindings including the conversion of a Felix closure object
to a C function pointer/void *client_data pair .. but the actual
interface code is quite messy and long winded (20 lines at least).
At least some of it begs for a language extension to simplify it:)

If Eiffel can do this more easily I'd love to see how .. does
it escape by not having first class functions perhaps ..?

I would be dumbfouned if ANY language other than C, C++, or a language
which is an extension of C or C++, will come even close to what
Felix can do -- it supports not only interfacing to C and C++,
it manages the dependency graph as well, to ensure only used C
code is instantiated, provides conditional compilation,
AND the instantiation is *polymorphic* on top of all that,
in addition to functions and types (as above) procedures,=20
values, inline expressions, inline statements, and floating
header and body code are also supported, along with
several 'shortcuts' (the example above are all special
cases using shortcuts .. :)

The high level of sophistication of the 'FFI' system=20
isn't just for 'interfacing to C': almost all the primitives --
and thus the language semantics -- are actually defined in
the library using these tools. There is, for example,
no integer type in Felix .. it has to be defined by the user:

	type int =3D "int";

and you can just as easily define:

	type int =3D "long long int";

or

	type int =3D "char";

and more importantly, you can (I hope!!!!) define your basic
types as Microsoft CLI .NET data types and *presto* Felix is
a .NET language.

Of course you can't add integers until you define:

	fun add: int * int -> int =3D "$1 + $2";
	// the name 'add' is special, and names the infix + operator too

so for example the entire numerical system is defined by the user --
usually by just including the standard library.

It kinds of makes 'integer arithmetic performance testing' a joke:
since the operations are all user defined bindings to C anyhow,
it begs the question "which integers and operations are you=20
talking about?"

> 	then you must call that library
> 	with JAVA: write an additional C library that is a JNI/C proxy stub
> 		it is not JAVA
> 		it is boring
> 		it is not interesting
> 	Same with Tcl and many other languages
> 	C and C++ are naturally privileged
> 	EIFFEL do it in one line
>=20
> And from an other point de vue, it is not interresting because CORBA (O=
RBIT),=20
> client/server protocols, are better ways of integrating libraries/compo=
nents=20
> in an huge project.


I agree 'it is boring' writing interfacing code, but it is essential
sometimes and it is an important feature of a language. Ocaml claims
a simple FFI, the Python one is hard, Tcl used to be easy but the newer
versions have made it much harder (IMHO).

I didn't know Eiffel could do this as easily as Felix, which was
specifically designed to make it easy -- in other words it is
something useful that might be learned from including such a test!


--=20
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,=20
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net