是否有任何原因导致 F# 不够聪明,无法优化以下代码?fast = 880
和slow = 8090
。
type Data = { fn: int * int -> int }
let fn (x, y) = x + y
let data = { fn = fn }
let mutable a = 0
let s = System.Diagnostics.Stopwatch()
s.Start()
for i in 0 .. 1000000000 do
a <- fn(i, i)
printfn "fast = %d" s.ElapsedMilliseconds
s.Restart()
for i in 0 .. 1000000000 do
a <- data.fn(i, i)
printfn "slow = %d" s.ElapsedMilliseconds