[squeak-dev] Fun with spock (NativeBoost FFI)

Lawson English lenglish5 at cox.net
Sun May 13 18:02:25 UTC 2012


So, thanks to Igor Stasenko, I've managed to learn how to (sorta) use 
the new NativeBoost FFI (spock). We (he) implemented a binding to a few 
of the gmplib functions. gmp is the GNU Multi-Precision Library.

Here is a simple benchmark of the Pharo factorial method vs the gmplib 
mpz_fac_ui() function. As might be expected, gmplib is  faster for any 
test larger than 13 factorial, as LargePositiveInteger  starts to become 
involved, and the speed differential becomes rather huge as larger 
integers are tested:

1000 factorial time to run with:
squeak: 2 ms      gmplib: 0.004 ms   ratio: 50.0
11000 factorial time to run with:
squeak: 354 ms      gmplib: 0.191 ms   ratio: 185.34031413612567
[...]
91000 factorial time to run with:
squeak: 34598 ms      gmplib: 4.759 ms   ratio: 727.0014708972473



Running on a Mac OS X Snow Leopard 2.8Ghz, with NBCog and 1.4 Pharo image.

benchmark:

a := GMPzWrapper new.

1000 to: 100000 by: 10000 do:
[:i|
    squeakTime :=  [ i factorial] timeToRun.
    Transcript show:  i asString, ' factorial time to run with:';cr.
    Transcript show:  'squeak: ', (squeakTime) asString, ' ms '.
    gmpTime :=  [100 timesRepeat: [a prim_mpz_fac_ui: i]] timeToRun.
    Transcript show:  '     gmplib: ' , (gmpTime/1000.0) asString, ' ms  '.
    Transcript show: ' ratio: ', (squeakTime/(gmpTime/100.0))  
asString;cr;cr.
]


-- 
Squeak from the very start (introduction to Squeak and Pharo Smalltalk for the (almost) complete and compleate beginner).
https://www.youtube.com/playlist?list=PL6601A198DF14788D&feature=view_all



More information about the Squeak-dev mailing list