Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>This works, but I have two concerns. First, is the time needed to generate random data included in the benchmark?</p> </blockquote> <p>Yes it would. All of the random generation should be happening lazily.</p> <blockquote> <p>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> </blockquote> <p>This is expected (if I understand what you mean); the random values from <code>randoms gen</code> aren't going to be generated until they're needed (i.e. inside your benchmark loop).</p> <blockquote> <p>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> </blockquote> <p>You need either to be in <code>IO</code> or create an <code>StdGen</code> with an integer seed you supply, with <code>mkStdGen</code>.</p> <p>Re. your main question of how you should get the pRNG stuff out of your benchmarks, you should be able to evaluate the random input fully <em>before</em> your <code>defaultMain (benchmarks g)</code> stuff, with <code>evaluate</code> and <code>force</code> like:</p> <pre><code>import Control.DeepSeq(force) import Control.Exception(evaluate) myBench g = do randInputEvaled &lt;- evaluate $ force $ dataFun g defaultMain [ bench "MyFun" $ nf benchFun randInputEvaled ... </code></pre> <p>where <code>force</code> evaluates its argument to normal form, but this will still happen lazily. So to get it to be evaluated outside of <code>bench</code> we use <code>evaluate</code> to leverage monadic sequencing. You could also do things like call <code>seq</code> on the tail of each of the lists in your tuple, etc. if you wanted to avoid the imports.</p> <p>That kind of thing should work fine, unless you need to hold a huge amount of test data in memory. </p> <p><strong>EDIT</strong>: this method is also a good idea if you want to get your data from IO, like reading from the disk, and don't want that mixed in to your benchmarks.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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