【发布时间】:2011-10-06 00:01:00
【问题描述】:
我正在尝试分析我的程序。
我是这样编译的:
ghc -rtsopts -O3 -prof -auto-all Main.hs
然后运行:
./Main +RTS -p
并阅读Main.prof:
Fri Jul 15 13:06 2011 Time and Allocation Profiling Report (Final)
Main +RTS -p -RTS
total time = 0.00 secs (0 ticks @ 20 ms)
total alloc = 266,726,496 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
trySub Main 0.0 14.3
ourPalindroms Main 0.0 15.0
isPalindromic Main 0.0 70.7
individual inherited
COST CENTRE MODULE no. entries %time %alloc %time %alloc
MAIN MAIN 1 0 0.0 0.0 0.0 100.0
CAF Main 240 10 0.0 0.0 0.0 100.0
asSquareSum Main 253 0 0.0 0.0 0.0 0.0
squares Main 252 2 0.0 0.1 0.0 0.1
maxN Main 248 1 0.0 0.0 0.0 0.0
ourPalindroms Main 247 1 0.0 15.0 0.0 85.7
isPalindromic Main 249 1000000 0.0 70.7 0.0 70.7
main Main 246 1 0.0 0.0 0.0 14.3
asSquareSum Main 250 1998 0.0 0.0 0.0 14.3
trySub Main 251 1998 0.0 14.3 0.0 14.3
CAF GHC.IO.Handle.FD 176 2 0.0 0.0 0.0 0.0
CAF GHC.IO.Encoding.Iconv 137 2 0.0 0.0 0.0 0.0
CAF GHC.Conc.Signal 130 1 0.0 0.0 0.0 0.0
我的程序这么牛的速度其实是骗人的:
[.../P125]$ time ./Main +RTS -p
...output...
real 0m4.995s
user 0m4.977s
sys 0m0.010s
(是的,我尝试在有和没有time 的情况下运行,而分析器一直在撒谎)
我能做什么?
[.../P125]$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.3
操作系统 Mac OS X 10.6.8。我很确定我已经从自制软件安装了ghc
【问题讨论】:
-
不知道发生了什么,但优化会干扰分析。尝试删除
-O3标志。 -
试过了,谢谢。没有任何改变
-
这可能是一个 GHC 错误,请参阅 #5282。有传言称它会与
-threaded一起消失。 -
它确实消失了!能否请您写下您的评论作为答案,以便我接受?
-
@Peter:代表 Stack Overflow Janitorial Reserve Corps(即 10k 用户)和 valya,是的,这是一个答案(通过建议
-threaded)。请保持原样,以便其他人更容易找到,并且问题将显示为已接受的答案。