查看使用*.prof
生成的+RTS -p
文件并启用了分析编译,我看到很多名为\
的子例程:
COST CENTRE MODULE %time %alloc
main.\.\.\ Main 74.1 85.8
unstreamChunks/inner Data.Text.Internal.Lazy.Fusion 11.9 8.6
inverseLetters.\ Main 4.5 1.7
main.\.\.\.(...) Main 2.9 1.0
main.\.\.\.(...) Main 2.8 1.0
unstreamChunks/resize Data.Text.Internal.Lazy.Fusion 1.2 0.8
unstreamChunks/outer Data.Text.Internal.Lazy.Fusion 1.1 0.5
对我来说看起来很神秘。这些代表什么?
答案 0 :(得分:17)
让
public message getDetailedMessage(int message_id)
{
message msg = new message();
if(context.messages.Any(mesg => (mesg.C_From == CurrentUser.Id && mesg.id == message_id) || (mesg.Receivers.Any(receiver => receiver.ReceiverId == CurrentUser.Id && receiver.MessageId == message_id))))
{
msg = context.messages.Where(mesg => mesg.id == message_id).FirstOrDefault();
msg.Status = "R";
context.SaveChanges();
}
else
{
msg.MDTO.HasError = true;
msg.MDTO.Error = "You do not have the permission to read this inbox";
}
return msg;
}
并使用
运行import Control.Monad
main = do
forM_ [1..1000] $ \i ->
if mod i 2 == 0 then putStrLn "Foo"
else print i
之后
ghc -rtsopts -prof -fprof-auto z.hs && ./z +RTS -p && cat z.prof
反斜杠显示堆栈级别you can set names for each one
COST CENTRE MODULE %time %alloc
main.\ Main 80.0 84.4
main Main 20.0 13.2
CAF GHC.IO.Handle.FD 0.0 2.1
现在
forM_ [1..1000] $ \i ->
{-# SCC "myBranch" #-}
if mod i 2 == 0 then putStrLn "Foo"
else print i
(添加@trVoldemort评论)
此外,COST CENTRE MODULE %time %alloc
myBranch Main 90.0 84.4
main Main 10.0 13.2
CAF GHC.IO.Handle.FD 0.0 2.1
似乎用于涉及计算的(...)
作业
let
带有配置文件输出
data T = T Int (IO ()) (IO ())
main =
forM_ [T (mod i 2) (putStrLn "Foo") (print i) | i <- [1..1000]] $ \q ->
let T a b c = q -- Will be `(...)`
in if a == 0 then b else c
使用SCC编译指示
main.\ Main
main.\.b Main
main.\.c Main
main.\.(...) Main
main.\.a Main
和输出
forM_ [T (mod i 2) (putStrLn "Foo") (print i) | i <- [1..1000]] $ \q ->
let T a b c = {-# SCC "myBind" #-} q
in if a == 0 then b else c