本文介绍了F# FSharpMap 与字典性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道 F# 不可变 Map 对标准字典的性能如何.

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 lines and thousands of elements.

内存使用情况如何?

谢谢

推荐答案

请参阅 Visual F# 2010 for Technical Computing 第 241-242 页优化:使用可变数据结构".显示 Dictionary 在非常相似的设置中运行速度比 Map 快 5-40 倍,将整数上的频率作为唯一键数量的函数进行计数.

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.

一般来说,像 Map 这样的纯函数式数据结构不仅在串行情况下非常慢,而且会破坏整个并行程序的可扩展性.我最近就这个问题进行了讲座.

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.

顺便说一句,别忘了有一个 Seq.countBy 函数!

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

这篇关于F# FSharpMap 与字典性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 05:21