i tried to code to calculate time that a function costs
list <- buildlist 10000 10000
starttime <- getClockTime
let sortedlist = quicksort list
endtime <- getClockTime
let difftime = diffClockTimes endtime starttime
function buildlist:
buildlist :: Int -> Int -> IO [Int]
buildlist n m = do
seed <- getStdGen
let l = randomRs (0, m) seed
let list = take n l
return list
function quicksort:
quicksort [] = []
quicksort (x:xs) =
let head = [a|a<-xs,a<=x]
tail = [a|a<-xs,a>x]
in quicksort head ++ [x] ++ quicksort tail
first question: when i output the difftime, it is always zero no matter how long the list is.
second one: i wonder what ">>=" in the code from Real World Haskell means.
getClockTime >>= (\(TOD sec _) -> return sec)
third: i write this to get tdSec and tdPicosec from a TimeDiff variable. is there any easier way?
time <-(\(TimeDiff _ _ _ _ _ s ps) -> return [ ( \a -> fromIntegral a :: Double ) s , ( \a -> fromIntegral a :: Double ) ps ] ) difftime
list
?sortedList
is never used. Why did you expect it to report a non-zero time?