<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<style id="EHTipGlobalStyle">.EHTipToolTip * {background: inherit;font-family: inherit;font-size: inherit;font-size-adjust: none;font-stretch: normal;line-height: inherit;font-variant: normal;border: 0px;text-transform: inherit;color: inherit;font-style: inherit;text-decoration: inherit;margin: 0px 0px 0px 0px;padding: 0px 0px 0px 0px;float: none;display: inline;cursor: default;}
.EHTipReplacer, .EHTipKey, .EHTipAudio {cursor: pointer;}
.EHTipToolTip hr {margin: 0.4em 0;display: block;border: 1px inset;}
.EHTipTranslation {font-style: normal;}
.EHTipTranslation a {color: #000099;font-style: normal;text-decoration: none;}
.EHTipTranslation a:hover {background: inherit;color: #000000;text-decoration: underline;}
</style>
</head>
<body style="background-color: rgb(255, 255, 255); color: rgb(0, 0,
0);" bgcolor="#FFFFFF" text="#000000">
HI,<br>
<br>
This is not real benchmark. I have a function called inside two
getCurrentTime.<br>
I had a request to handle over 100 comparisons per second, and
couldn't achieve that with monadic version because it was too slow.<br>
(I do not need the solution for the problem, i.e. how to speed it
up. I moved the function out of IO and it is fine now.)<br>
<br>
I must admit that I didn't have the slightest idea that the
performance could be so different (a million times).<br>
I'm not a Haskell expert and I just want to know what is eating
time, so I do not do that in my own functions, or at least to be
aware of the possible problem.<br>
<br>
<br>
"...any of the two taking advantage of computations previously
performed..."<br>
I load both images and than run functions in both orders, and the
results were the same.<br>
<br>
<br>
BTW, this was the function:<br>
<br>
diffA :: Image PixelRGB8 -> Image PixelRGB8 -> Image
PixelRGBA8<br>
diffA i1@(Image { imageWidth = w, imageHeight = h }) i2 =
generateImage (pixGenA i1 i2) w h <br>
<br>
pixGenA :: Image PixelRGB8 -> Image PixelRGB8 -> Int -> Int
-> PixelRGBA8<br>
pixGenA i1 i2 x y = <br>
if p1 == p2 <br>
then PixelRGBA8 0 0 0 0<br>
else PixelRGBA8 r g b 254<br>
where<br>
p1@(PixelRGB8 r g b) = pixelAt i1 x y<br>
p2 = pixelAt i2 x y<br>
<br>
<br>
The other is exactly the same, but has "withImage" instead of
"generateImage". (and pixGenM is monadic)<br>
<br>
diff2 :: Image PixelRGB8 -> Image PixelRGB8 -> IO (Image
PixelRGBA8)<br>
diff2 i1@(Image { imageWidth = w, imageHeight = h }) i2 = withImage
w h (pixGenM i1 i2) <br>
<br>
pixGenM :: Monad m => Image PixelRGB8 -> Image PixelRGB8 ->
Int -> Int -> m PixelRGB8<br>
...<br>
<br>
<br>
Not much wisdom in it. :-)<br>
<br>
<br>
vlatko<br>
<br>
<br>
<blockquote style="border-left: 2px solid #330033 !important;
border-right: 2px solid #330033 !important; padding: 0px 15px 0px
15px; margin: 8px 2px;"
cite="mid:CADZnDvCWgaCjSq81W4hWwv=mpVUwg15dgGG3FbQbg0rXgz27Mw@mail.gmail.com"
type="cite"><!--[if !IE]><DIV style="border-left: 2px solid #330033; border-right: 2px solid #330033; padding: 0px 15px; margin: 2px 0px;"><![endif]--><span
style="color:#000000;" class="headerSpan">
<div class="moz-cite-prefix">-------- Original Message --------<br>
Subject: Re: [Haskell-cafe] JuicyFruit - explanation of speed
difference of pure and monadic image generation<br>
From: Alp Mestanogullari <a class="moz-txt-link-rfc2396E" href="mailto:alpmestan@gmail.com"><alpmestan@gmail.com></a><br>
To: Joey Adams <a class="moz-txt-link-rfc2396E" href="mailto:joeyadams3.14159@gmail.com"><joeyadams3.14159@gmail.com></a><br>
Cc: The Haskell Cafe <a class="moz-txt-link-rfc2396E" href="mailto:haskell-cafe@haskell.org"><haskell-cafe@haskell.org></a>,
<a class="moz-txt-link-abbreviated" href="mailto:vlatko.basic@gmail.com">vlatko.basic@gmail.com</a><br>
Date: 20.03.2014 15:43<br>
</div>
<br>
<br>
</span>
<p dir="ltr">Could it be because you are calling withImage in IO
whereas generateImage coes through ST? A lot of the nice
performance numbers of JuicyPixels come from its carefully
tailored ST usage, which in turn comes from theefficiency of
unboxed mutable vectors (as in the "vector" package). </p>
<p dir="ltr">So could you post the benchmark result for a version
where you runST on the result of withImage? That should be a
fairer comparison. Also, writing a criterion benchmark would
help and make sure the functions are run properly without any of
the two taking advantage of computations previsouly performed by
the other.</p>
<!--[if !IE]></DIV><![endif]--></blockquote>
<br>
</body>
</html>