I tried to encode to calculate the time during which the function stands
list <- buildlist 10000 10000
starttime <- getClockTime
let sortedlist = quicksort list
endtime <- getClockTime
let difftime = diffClockTimes endtime starttime
feature list:
buildlist :: Int -> Int -> IO [Int]
buildlist n m = do
seed <- getStdGen
let l = randomRs (0, m) seed
let list = take n l
return list
quicksort function:
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 diffftime, it is always zero, regardless of how long this list is.
second: Interestingly, "→ =" in the code from Real World Haskell means.
getClockTime >>= (\(TOD sec _) -> return sec)
Third: I am writing this to get tdSec and tdPicosec from the TimeDiff variable . is there an easier way?
time <-(\(TimeDiff _ _ _ _ _ s ps) -> return [ ( \a -> fromIntegral a :: Double ) s , ( \a -> fromIntegral a :: Double ) ps ] ) difftime
source
share