[squeak-dev] Alien vs. FFI benchmarks (Re: Trying to load ALienOpenGL into 4.1 alpha...)

Andreas Raab andreas.raab at gmx.de
Tue Mar 23 07:09:41 UTC 2010


On 3/22/2010 9:21 PM, Andreas Raab wrote:
>> Also, I was under the impression that Alien FFI was faster than the
>> standard FFI.
>
> Oh, dear. This is hearsay, right? I.e., neither you nor anyone who
> claims it have ever ever run an actual benchmark, have you?

I thought it'd be fun to make a little benchmark so here we go. I'm 
using the most trivial example, namely the call to glGetError() which 
should be done early and often :-) Using the FFI (from CroquetGL) this 
looks like here:

	ogl := OpenGL newIn: (0 at 0 corner: 10 at 10).
	time := [1 to: 1000000 do:[:i| ogl glGetError]] timeToRun.
	ogl destroy.

This takes about 435 msecs. Now the same with AlienOpenGL in Pharo:

	drawable := OpenGLSurface newIn: (0 at 0 corner: 10 at 10).
	ogl := AlienOpenGLLibrary uniqueInstance.
	time := [1 to: 1000000 do:[:i| ogl glGetError]] timeToRun.
	drawable close.

This takes 8372 msecs. Whoopsie. That's a factor of 20x AlienOpenGL is 
slower for the same C call. But okay, that may not be a fair comparison 
due to the naive use of Alien. Let's be more clever, look up the method 
just once and invoke it:

	drawable := OpenGLSurface newIn: (0 at 0 corner: 10 at 10).
	ogl := AlienOpenGLLibrary uniqueInstance.
	alienMethod := ogl alienMethodNamed: 'glGetError'.
	time := [1 to: 1000000 do:[:i|
		error := GLEnum new.
		alienMethod primFFICallResult: error.
	]] timeToRun.
	drawable close.

This still takes 3589 msecs. Whoops, it did it again. Even with the more 
elaborate use Alien is still 8x slower than the FFI. That's the cost of 
doing marshalling in Squeak and the effect it has on Alien performance 
when compared with the FFI.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list