Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Out of curiosity, I ran this with llvm:</p> <blockquote> <p>ghc Test.hs -O2 -XBangPatterns -fllvm -optlo-O3</p> </blockquote> <p>and it took it down from 60ms to 24ms. Still not ideal.</p> <p>So, one of the first things I'll do when I want to know why a benchmark like this is so slow, is dump the prepared core. That is, the core after optimisations.</p> <blockquote> <p>ghc Test.hs -O2 -ddump-prep -dsuppress-all -XBangPatterns > Test.hscore</p> </blockquote> <p>After looking through the core, I eventually found $wa, where the iterative loop is defined. It turns out it's making surprisingly many index bound checks. See, I usually use Data.Vector.Unboxed, which has "unsafeRead" and "unsafeIndex" functions, to remove bounds checks. These would be useful here. Personally, I think the vector package is superior.</p> <p>If you look at $wa, you'll notice it's unboxing the arguments at the start:</p> <pre><code>case w_s3o9 of _ { STUArray l_s3of u_s3oi ds1_s3ol ds2_s3oH -&gt; case l_s3of of wild2_s3os { I# m_s3oo -&gt; case u_s3oi of wild3_s3ot { I# n1_s3ov -&gt; case ds1_s3ol of wild4_s3oC { I# y1_s3oE -&gt; </code></pre> <p>this looks bad, but it turns out in the recursive call it's using a specialised version, integrate_$s$wa, with unboxed integers etc. This is good.</p> <p>In summary, I think you should get a good improvement by using vector with unsafe indexing.</p> <p>Edit: here is a modified version with Data.Vector. It runs in about 7ms. For <em>good</em> vector code, I think the only slowness compared to C should be due to incomplete alias analysis. <a href="https://gist.github.com/amosr/6026995">https://gist.github.com/amosr/6026995</a></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