Quicksort + Profiling
Question
i'm trying to profile a quicksort code. the code is as follows:
qsort [] = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)
please help me out!
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow