Where is the `unsafeAt` function? I can'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't complete in 3 minutes, where as a new C++ version I wrote completes in 45 seconds (because I didn'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'.<br><br>It seems mysterious that such an innocent program is so obscure to write "correctly" 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"><<a href="mailto:ekirpichov@gmail.com">ekirpichov@gmail.com</a>></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 <<a href="mailto:kizzx2%2Bhaskell@gmail.com">kizzx2+haskell@gmail.com</a>>:<br>
<div><div></div><div class="h5">> Here is an updated version using Data.Array.Unboxed <a href="http://ideone.com/YXuVL" target="_blank">http://ideone.com/YXuVL</a><br>
> And the profile <a href="http://hpaste.org/49940" target="_blank">http://hpaste.org/49940</a><br>
><br>
> Still taking 5+ minutes...<br>
><br>
> Chris<br>
><br>
> On Sun, Aug 7, 2011 at 5:20 PM, Daniel Fischer<br>
> <<a href="mailto:daniel.is.fischer@googlemail.com">daniel.is.fischer@googlemail.com</a>> wrote:<br>
>><br>
>> On Sunday 07 August 2011, 10:52:20, Max Bolingbroke wrote:<br>
>> > In short I don't see how to get further without changing the algorithm<br>
>> > or doing some hacks like manual unrolling. Maybe someone else has some<br>
>> > ideas?<br>
>><br>
>> Well, the C# implementation uses arrays for lookup while the Haskell<br>
>> version uses list lookups<br>
>><br>
>> in (tens !! fromIntegral t) ++ wordify x<br>
>><br>
>> and case'd functions<br>
>><br>
>> lenTens 0 = 0<br>
>> lenTens 1 = 3<br>
>> lenTens 2 = 6<br>
>> lenTens 3 = 6<br>
>> lenTens 4 = 5<br>
>> lenTens 5 = 5<br>
>> lenTens 6 = 5<br>
>> lenTens 7 = 7<br>
>> lenTens 8 = 6<br>
>> lenTens 9 = 6<br>
>><br>
>> wordify is only called once at the end, so that should not have a<br>
>> measurable impact, but the lenXXXs might.<br>
>> I'm not sure what<br>
>><br>
>> CaseLen.$wlenTens :: <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a> -> <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a><br>
>> [GblId,<br>
>> Arity=1,<br>
>> Str=DmdType L,<br>
>> Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=1, Value=True,<br>
>> ConLike=True, Cheap=True, Expandable=True,<br>
>> Guidance=IF_ARGS [12] 11 0}]<br>
>> CaseLen.$wlenTens =<br>
>> \ (ww_shY :: <a href="http://GHC.Prim.Int#" target="_blank">GHC.Prim.Int#</a>) -><br>
>> case ww_shY of _ {<br>
>> __DEFAULT -><br>
>> CaseLen.lenTens1<br>
>> `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>
>> :: <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>
>> 0 -> 0;<br>
>> 1 -> 3;<br>
>> 2 -> 6;<br>
>> 3 -> 6;<br>
>> 4 -> 5;<br>
>> 5 -> 5;<br>
>> 6 -> 5;<br>
>> 7 -> 7;<br>
>> 8 -> 6;<br>
>> 9 -> 6<br>
>> }<br>
>><br>
>> means at a lower level, but it's certainly worth trying out whether an<br>
>> unboxed array lookup is faster.<br>
><br>
><br>
</div></div><div><div></div><div class="h5">> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
><br>
><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>