Optimizing Haskell code

前端 未结 6 1237
轮回少年
轮回少年 2020-12-31 04:20

I\'m trying to learn Haskell and after an article in reddit about Markov text chains, I decided to implement Markov text generation first in Python and now in Haskell. Howev

6条回答
  •  情话喂你
    2020-12-31 04:54

    As Don suggested, look into using the stricer versions o your functions: insertWithKey' (and M.insertWith' since you ignore the key param the second time anyway).

    It looks like your code probably builds up a lot of thunks until it gets to the end of your [String].

    Check out: http://book.realworldhaskell.org/read/profiling-and-optimization.html

    ...especially try graphing the heap (about halfway through the chapter). Interested to see what you figure out.

提交回复
热议问题