Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could try using imperative hash maps from the hashtables package: <a href="http://hackage.haskell.org/package/hashtables" rel="nofollow noreferrer">http://hackage.haskell.org/package/hashtables</a> I remember I once got a moderate speedup compared to Data.Map. I wouldn't expect anything spectacular though.</p> <p><strong>UPDATE</strong></p> <p>I simplified your python code so I could test it on a single big file (100 million lines):</p> <pre><code>import sys histogram={} for word in sys.stdin.readlines(): if word in histogram: histogram[word] = histogram[word]+1 else: histogram[word] = 1 print histogram.get("the") </code></pre> <p>Takes 6.06 seconds</p> <p>Haskell translation using hashtables:</p> <pre><code>{-# LANGUAGE OverloadedStrings #-} import qualified Data.ByteString.Char8 as T import qualified Data.HashTable.IO as HT main = do ls &lt;- T.lines `fmap` T.getContents h &lt;- HT.new :: IO (HT.BasicHashTable T.ByteString Int) flip mapM_ ls $ \w -&gt; do r &lt;- HT.lookup h w case r of Nothing -&gt; HT.insert h w (1::Int) Just c -&gt; HT.insert h w (c+1) HT.lookup h "the" &gt;&gt;= print </code></pre> <p>Run with a large allocation area: <code>histogram +RTS -A500M</code> Takes 9.3 seconds, with 2.4% GC. Still quite a bit slower than Python but not too bad.</p> <p>According to the <a href="http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/runtime-control.html#rts-opts-compile-time" rel="nofollow noreferrer">GHC user guide</a>, you can change the RTS options while compiling: </p> <blockquote> <p>GHC lets you change the default RTS options for a program at compile time, using the -with-rtsopts flag (Section 4.12.6, “Options affecting linking”). A common use for this is to give your program a default heap and/or stack size that is greater than the default. For example, to set -H128m -K64m, link with -with-rtsopts="-H128m -K64m".</p> </blockquote>
    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