<div dir="auto">The critical feature of whnf (as I understand it) is that GHC does not use the static argument transformation. The function passed to "go" therefore doesn't inline into it. So you'll have to write your version in some fashion that similarly prevents undesirable inlining. Could you just copy the code and specialize it to the desired type?</div><div class="gmail_extra"><br><div class="gmail_quote">On Mar 18, 2017 1:32 PM, "Richard Eisenberg" <<a href="mailto:rae@cs.brynmawr.edu">rae@cs.brynmawr.edu</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Apologies for a newbie question, but I am seeking advice on how to benchmark a pure function that returns an unlifted type. I've heard tell that `criterion` is good for benchmarking, and so I'm using that library (but have no particular allegiance to it, if something else is better).<br>
<br>
Specifically, I'm comparing a function over unlifted types with the same function written over lifted types, trying to observe how much we pay for the boxing/unboxing. To benchmark the lifted version, I just use criterion's whnf function. That seems to be working splendidly. Of course, whnf doesn't work over unlifted types, so I found its source code and inlined it. This compiles. But it doesn't work! No matter what I do, the unlifted version measures in the nanoseconds. I'm guessing that GHC "cleverly" is avoiding recomputation. How can I stop this?<br>
<br>
Here is my code:<br>
<br>
> main :: IO ()<br>
> main = do<br>
>   initializeTime<br>
>   let lifted   = whnf fastSumPrimes 100000<br>
><br>
>       unlifted = Benchmarkable go<br>
>         where<br>
>           go n<br>
>             | n <= 0    = return ()<br>
>             | otherwise = let x = fastSumPrimes# 100000# in go (n-1)<br>
><br>
>   benchmark lifted<br>
>   benchmark unlifted<br>
<br>
I've tried increasing the argument in the unlifted case, to no avail. I've also tried using `case` instead of `let`. -ddump-simpl suggests that fastSumPrimes# is really being called, but I'm dubious.<br>
<br>
Can anyone offer advice?<br>
<br>
Thanks!<br>
Richard<br>
______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/haskell-<wbr>cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br></div>