相关疑难解决方法(0)

为什么Seq.iter和Seq.map这么慢?

在F#中考虑以下代码:

let n = 10000000
let arr = Array.init n (fun _ -> 0)

let rec buildList n acc i = if i = n then acc else buildList n (0::acc) (i + 1)
let lst = buildList n [] 0

let doNothing _ = ()
let incr x = x + 1

#time

arr |> Array.iter doNothing         // this takes 14ms
arr |> Seq.iter doNothing           // this takes 74ms

lst |> List.iter doNothing          // this takes 19ms
lst |> …
Run Code Online (Sandbox Code Playgroud)

performance f# seq

11
推荐指数
1
解决办法
1603
查看次数

标签 统计

f# ×1

performance ×1

seq ×1