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

2011-04-12 Thread John Lato
From: Gregory Collins g...@gregorycollins.net On Mon, Apr 11, 2011 at 3:55 PM, Serguei Son serguei@gmail.com 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

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] mapM (return .

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 uzytkown...@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] -- Felipe. ___ Haskell-Cafe mailing list

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

2011-04-11 Thread Serguei Son
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

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

2011-04-11 Thread Serguei Son
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 =

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

2011-04-11 Thread Serguei Son
Serguei Son serguei.son at 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

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 serguei@gmail.com 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

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 serguei@gmail.com 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