Where is the `unsafeAt` function? I can&#39;t seem to find it (<a href="http://haskell.org/hoogle/?hoogle=unsafeat">http://haskell.org/hoogle/?hoogle=unsafeat</a>).<br><br>For reference I have asked the same question on StackOverflow. One person suggested that the reason might be that Int64 on Windows is broken (<a href="http://stackoverflow.com/questions/6970904/analyzing-slow-performance-of-a-haskell-program/6976448#6976448">http://stackoverflow.com/questions/6970904/analyzing-slow-performance-of-a-haskell-program/6976448#6976448</a>).<br>

<br>I tried the same test on Arch Linux x64 (GHC 7.0.3) but it still can&#39;t complete in 3 minutes, where as a new C++ version I wrote completes in 45 seconds (because I didn&#39;t want to use Mono for benchmarks. For reference here is the C++ implementation <a href="http://ideone.com/vZGhh">http://ideone.com/vZGhh</a> (Again, ironically shorter than Haskell and actually looks quite clean))<br>

<br>The profile under x64 Linux is similar to the one posted before -- most allocations and time spent in wordLength&#39;.<br><br>It seems mysterious that such an innocent program is so obscure to write &quot;correctly&quot; in Haskell :P<br>

<br>Chris<br><br><div class="gmail_quote">On Mon, Aug 8, 2011 at 1:40 AM, Eugene Kirpichov <span dir="ltr">&lt;<a href="mailto:ekirpichov@gmail.com">ekirpichov@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

What about using unsafe array indexing operations? (i.e. array `unsafeAt` index)<br>
<br>
2011/8/7 Chris Yuen &lt;<a href="mailto:kizzx2%2Bhaskell@gmail.com">kizzx2+haskell@gmail.com</a>&gt;:<br>
<div><div></div><div class="h5">&gt; Here is an updated version using Data.Array.Unboxed  <a href="http://ideone.com/YXuVL" target="_blank">http://ideone.com/YXuVL</a><br>
&gt; And the profile <a href="http://hpaste.org/49940" target="_blank">http://hpaste.org/49940</a><br>
&gt;<br>
&gt; Still taking 5+ minutes...<br>
&gt;<br>
&gt; Chris<br>
&gt;<br>
&gt; On Sun, Aug 7, 2011 at 5:20 PM, Daniel Fischer<br>
&gt; &lt;<a href="mailto:daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On Sunday 07 August 2011, 10:52:20, Max Bolingbroke wrote:<br>
&gt;&gt; &gt; In short I don&#39;t see how to get further without changing the algorithm<br>
&gt;&gt; &gt; or doing some hacks like manual unrolling. Maybe someone else has some<br>
&gt;&gt; &gt; ideas?<br>
&gt;&gt;<br>
&gt;&gt; Well, the C# implementation uses arrays for lookup while the Haskell<br>
&gt;&gt; version uses list lookups<br>
&gt;&gt;<br>
&gt;&gt;                      in (tens !! fromIntegral t) ++ wordify x<br>
&gt;&gt;<br>
&gt;&gt; and case&#39;d functions<br>
&gt;&gt;<br>
&gt;&gt; lenTens 0 = 0<br>
&gt;&gt; lenTens 1 = 3<br>
&gt;&gt; lenTens 2 = 6<br>
&gt;&gt; lenTens 3 = 6<br>
&gt;&gt; lenTens 4 = 5<br>
&gt;&gt; lenTens 5 = 5<br>
&gt;&gt; lenTens 6 = 5<br>
&gt;&gt; lenTens 7 = 7<br>
&gt;&gt; lenTens 8 = 6<br>
&gt;&gt; lenTens 9 = 6<br>
&gt;&gt;<br>
&gt;&gt; wordify is only called once at the end, so that should not have a<br>
&gt;&gt; measurable impact, but the lenXXXs might.<br>
&gt;&gt; I&#39;m not sure what<br>
&gt;&gt;<br>
&gt;&gt; CaseLen.$wlenTens :: <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a> -&gt; <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a><br>
&gt;&gt; [GblId,<br>
&gt;&gt;  Arity=1,<br>
&gt;&gt;  Str=DmdType L,<br>
&gt;&gt;  Unf=Unf{Src=&lt;vanilla&gt;, TopLvl=True, Arity=1, Value=True,<br>
&gt;&gt;         ConLike=True, Cheap=True, Expandable=True,<br>
&gt;&gt;         Guidance=IF_ARGS [12] 11 0}]<br>
&gt;&gt; CaseLen.$wlenTens =<br>
&gt;&gt;  \ (ww_shY :: <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a>) -&gt;<br>
&gt;&gt;    case ww_shY of _ {<br>
&gt;&gt;      __DEFAULT -&gt;<br>
&gt;&gt;        CaseLen.lenTens1<br>
&gt;&gt;        `cast` (CoUnsafe <a href="http://GHC.Types.Int" target="_blank">GHC.Types.Int</a> <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a><br>
&gt;&gt;                :: <a href="http://GHC.Types.Int" target="_blank">GHC.Types.Int</a> ~ <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a>);<br>
&gt;&gt;      0 -&gt; 0;<br>
&gt;&gt;      1 -&gt; 3;<br>
&gt;&gt;      2 -&gt; 6;<br>
&gt;&gt;      3 -&gt; 6;<br>
&gt;&gt;      4 -&gt; 5;<br>
&gt;&gt;      5 -&gt; 5;<br>
&gt;&gt;      6 -&gt; 5;<br>
&gt;&gt;      7 -&gt; 7;<br>
&gt;&gt;      8 -&gt; 6;<br>
&gt;&gt;      9 -&gt; 6<br>
&gt;&gt;    }<br>
&gt;&gt;<br>
&gt;&gt; means at a lower level, but it&#39;s certainly worth trying out whether an<br>
&gt;&gt; unboxed array lookup is faster.<br>
&gt;<br>
&gt;<br>
</div></div><div><div></div><div class="h5">&gt; _______________________________________________<br>
&gt; Haskell-Cafe mailing list<br>
&gt; <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
</div></div><font color="#888888">--<br>
Eugene Kirpichov<br>
Principal Engineer, Mirantis Inc. <a href="http://www.mirantis.com/" target="_blank">http://www.mirantis.com/</a><br>
Editor, <a href="http://fprog.ru/" target="_blank">http://fprog.ru/</a><br>
</font></blockquote></div><br>