开发者

F# FSharpMap vs Dictionary performance

开发者 https://www.devze.com 2023-01-10 13:11 出处:网络
I was wondering how does the F# immutable Map perform against the standard Dictionary. I am writing a count function (for each line lookup increment set) to use on large files with millions of l开发者

I was wondering how does the F# immutable Map perform against the standard Dictionary.

I am writing a count function (for each line lookup increment set) to use on large files with millions of l开发者_Go百科ines and thousands of elements.

What about the memory usage?

Thanks


I was wondering how does the F# immutable Map perform against the standard Dictionary.

See Visual F# 2010 for Technical Computing pages 241-242 "Optimization: Use mutable data structures". Shows a Dictionary running 5-40× faster than a Map in the very similar setting of counting the frequencies on ints as a function of the number of unique keys.

In general, purely functional data structures like Map are not only extremely slow in the serial case but they destroy scalability of entire parallel programs. I gave a lecture on this recently.

BTW, don't forget there is a Seq.countBy function!

0

精彩评论

暂无评论...
验证码 换一张
取 消