<div dir="ltr">Thanks, I suspect you are right that caching wouldn't help. However, there are several places that unboxed vectors might help me, so thanks for that tip.<div>D</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 3, 2017 at 7:22 PM, Michael Snoyman <span dir="ltr"><<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">The real answer here is to benchmark; there's no way to know for certain what will be faster in the abstract, especially without seeing your implementation. That said: in order for a caching algorithm to work, you're going to have to traverse your entire input list to perform a lookup. Meaning: I'd be surprised if caching sped up this case. But again, that's just a guess, benchmarking would be the only true answer.<div><br></div><div>Algorithms like this can often be significantly faster if you used an unboxed vector[1] to hold the Ints instead of a list, so if you're benchmarking, I'd recommend throwing that into the mix as well.</div><div><br></div><div>Finally: what were you considering using as a data structure to hold the cache? I would imagine that using a HashMap would sort of defeat the purpose in this case :)</div><div><br></div><div>Michael</div><div><br></div><div>[1] <a href="https://www.stackage.org/haddock/lts-8.21/vector-0.11.0.0/Data-Vector-Unboxed.html" target="_blank">https://www.stackage.org/<wbr>haddock/lts-8.21/vector-0.11.<wbr>0.0/Data-Vector-Unboxed.html</a></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Jul 4, 2017 at 5:09 AM, Dennis Raddle <span dir="ltr"><<a href="mailto:dennis.raddle@gmail.com" target="_blank">dennis.raddle@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hello, I have an application which could benefit from caching certain computations. For instance, I might have a function:<div><br></div><div>listToWord :: [Int] -> Word16</div><div><br></div><div>which takes an integer X in the input as referring to bit X in the output word, and sets the bits.</div><div><br></div><div>I have to run this computation many times within the inner loop. So I thought I could cache it. The only trouble is that it may not be any less expensive to convert the [Int] into a hash value, or use it as a key to look up a binary Map. </div><div><br></div><div>What do you think? Does Haskell hashing use some kind of optimized computation that's faster than me writing a loop by hand?</div><span class="m_3366832607585861666HOEnZb"><font color="#888888"><div><br></div><div>D</div><div><br></div></font></span></div>
<br></div></div>______________________________<wbr>_________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/haskell-caf<wbr>e</a><br>
Only members subscribed via the mailman list are allowed to post.<br></blockquote></div><br></div>
</blockquote></div><br></div>