Quicksort + Profiling
i'm trying to profile a quicksort code. the code is as follows:
qsort [] = []
qsort (x:xs) = qsort (filt开发者_运维知识库er (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
please help me out!
Assuming you use GHC, you can enable profiling with the -prof
flag (probably -auto-all
and -caf-all
for more detail).
Then you run your program with ./a.out +RTS -p
to generate the profiling result in a.out.prof
.
The profile only include the total time and memory spent on each function. Which may not be suitable for you, since there's only one function qsort
. Compile the program normally and run with ./a.out +RTS -sstderr
may have enough information already.
See
- http://www.haskell.org/ghc/docs/latest/html/users_guide/profiling.html for more profiling options in GHC.
- http://book.realworldhaskell.org/read/profiling-and-optimization.html for how to analyze the profiled info.
精彩评论