是否可以在Haskell中分析空间使用情况

Sim*_*mon 4 haskell

Erik讲座第12章通过介绍示例函数提到"改善空间使用" sumWith.

我代表懒惰版本和严格版本,如下所示.

sumWith1 v [] = v
sumWith1 v (x:xs) = sumWith1 (v+x) xs

sumWith2 v [] = v
sumWith2 v (x:xs) = (sumWith2 $! (v+x)) xs

test = sumWith1 0 [1..200000000]
Run Code Online (Sandbox Code Playgroud)

我想严格版本应该在某个级别上提高性能,因此我尝试验证杠杆GHC分析工具.

$ ghc --make -O2 -prof -auto-all -rtsopts -o test1
$ ./test1 +RTS -p -RTS
Run Code Online (Sandbox Code Playgroud)

更改sumWith1sumWith2at testfunction并再次执行test2.

以下是分析结果:http://pastie.org/4720019.

通过查看%alloc列,我看不出这两个函数之间的差异.

我的问题是如何改进测试用例以找到一些区别.换句话说,是否可以分析这种情况下的空间使用情况?

谢谢.

Don*_*art 6

使用GHC的堆分析器.

RWH,ch25中详细描述.这是一个完整的例子.