Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create data for Criterion benchmarks?
    primarykey
    data
    text
    <p>I am using <a href="http://hackage.haskell.org/package/criterion" rel="nofollow noreferrer">criterion</a> to benchmark my Haskell code. I'm doing some heavy computations for which I need random data. I've written my main benchmark file like this:</p> <pre><code>main :: IO () main = newStdGen &gt;&gt;= defaultMain . benchmarks benchmarks :: RandomGen g =&gt; g -&gt; [Benchmark] benchmarks gen = [ bgroup "Group" [ bench "MyFun" $ nf benchFun (dataFun gen) ] ] </code></pre> <p>I keep benchmarks and data genrators for them in different modules:</p> <pre><code>benchFun :: ([Double], [Double]) -&gt; [Double] benchFun (ls, sig) = fun ls sig dataFun :: RandomGen g =&gt; g -&gt; ([Double], [Double]) dataFun gen = (take 5 $ randoms gen, take 1024 $ randoms gen) </code></pre> <p>This works, but I have two concerns. First, is the time needed to generate random data included in the benchmark? I found <a href="https://stackoverflow.com/questions/6637968/how-to-use-criterion-to-measure-performance-of-haskell-programs">a question that touches on that subject</a> but honestly speaking I'm unable to apply it to my code. To check whether this happens I wrote an alternative version of my data generator enclosed within IO monad. I placed benchmarks list with main, called the generator, extracted the result with &lt;- and then passed it to the benchmarked function. I saw no difference in performance.</p> <p>My second concern is related to generating random data. Right now the generator once created is not updated, which leads to generating the same data within a single run. This is not a major problem, but nevertheless it would be nice to make it properly. Is there a neat way to generate different random data within each data* function? "Neat" means "without making data functions acquiring StdGen within IO"?</p> <p>EDIT: As noted in comment below I don't really care about data randomness. What is important to me is that the time needed to generate the data is not included in the benchmark.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload