[Haskell-cafe] Foreign function performance: monadic vs pure

Serguei Son serguei.son at gmail.com
Mon Apr 11 16:02:42 CEST 2011


Serguei Son <serguei.son <at> gmail.com> writes:

> 
> Felipe Almeida Lessa <felipe.lessa <at> gmail.com> writes:
> 
> > 
> > On Mon, Apr 11, 2011 at 10:14 AM, Maciej Marcin Piechotka
> > <uzytkownik2 <at> gmail.com> wrote:
> > >> main = mapM (\x -> return $! c_sin_u) [1..n]
> > > 0.012 s
> > 
> > This should be
> > 
> >   main = mapM (\x -> return $! c_sin_u x) [1..n]
> > 
> 
> So if I must use a safe function returning IO a,
> there is no way to improve its performance? To give you
> a benchmark, calling gsl_ran_ugaussian a million times
> in pure C takes only a second or two on my system.
> 

Also, please note that I can force the evaluation 
of c_sin, e.g. 

mapM (return . c_sin) [1..n] >>= (print $ foldl' (+) 0)

And it will still execute reasonably fast.






More information about the Haskell-Cafe mailing list