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

2011-04-12 Thread John Lato
> > From: Gregory Collins > > On Mon, Apr 11, 2011 at 3:55 PM, Serguei Son > wrote: > > 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

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

2011-04-11 Thread Gregory Collins
On Mon, Apr 11, 2011 at 3:55 PM, Serguei Son wrote: > 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. In the C version, are you

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

2011-04-11 Thread Anthony Cowley
On Mon, Apr 11, 2011 at 8:09 AM, Serguei Son wrote: > Consider two versions of sin wrapped: > foreign import ccall "math.h sin" >    c_sin_m :: CDouble -> IO CDouble Marking this call as unsafe (i.e. foreign import ccall unsafe "math.h sin") can improve performance dramatically. If the FFI call i

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

2011-04-11 Thread Serguei Son
Serguei Son gmail.com> writes: > 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. > Pls disregard the my previous post. I actually meant let lst = map c_sin [1..n] p

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

2011-04-11 Thread Serguei Son
Serguei Son gmail.com> writes: > > Felipe Almeida Lessa gmail.com> writes: > > > > > On Mon, Apr 11, 2011 at 10:14 AM, Maciej Marcin Piechotka > > gmail.com> wrote: > > >> main = mapM (\x -> return $! c_sin_u) [1..n] > > > 0.012 s > > > > This should be > > > > main = mapM (\x -> return

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

2011-04-11 Thread Serguei Son
Felipe Almeida Lessa gmail.com> writes: > > On Mon, Apr 11, 2011 at 10:14 AM, Maciej Marcin Piechotka > 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

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

2011-04-11 Thread Felipe Almeida Lessa
On Mon, Apr 11, 2011 at 10:14 AM, Maciej Marcin Piechotka 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] -- Felipe. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.

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

2011-04-11 Thread Maciej Marcin Piechotka
On Mon, 2011-04-11 at 12:09 +, Serguei Son wrote: > Consider two versions of sin wrapped: > foreign import ccall "math.h sin" > c_sin_m :: CDouble -> IO CDouble > and > foreign import ccall "math.h sin" > c_sin :: CDouble -> CDouble > > One can invoke them so: > > mapM c_sin_m [1..n]