
I'm new to Haskell. I'm apparently misunderstanding something here. When I run this program: --------- module Main where import System.Posix import System.CPUTime printTime = getCPUTime >>= putStrLn . show main = printTime >> sleep 5 >> printTime --------- It produces this output: 1430000000000 1430000000000 or similar. In any case, both the numbers are the same. Should the second number not reflect a time 5 seconds later than the first? I've tried this with both GHC and Hugs, and both give me the same thing. Thanks. Mike Benfield

On 2005-11-21 at 15:14EST Michael Benfield wrote:
I'm new to Haskell. I'm apparently misunderstanding something here.
When I run this program:
--------- module Main where
import System.Posix import System.CPUTime
printTime = getCPUTime >>= putStrLn . show
main = printTime >> sleep 5 >> printTime ---------
It produces this output: 1430000000000 1430000000000
or similar. In any case, both the numbers are the same. Should the second number not reflect a time 5 seconds later than the first? I've tried this with both GHC and Hugs, and both give me the same thing.
Should 'sleep 5' take any CPU time? -- Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk

getCPUTime gets the amount of CPU time used by the program so far, in
picoseconds (though with limited resolution). Use getClockTime from
System.Time to get the current clock time.
- Cale
On 21/11/05, Michael Benfield
I'm new to Haskell. I'm apparently misunderstanding something here.
When I run this program:
--------- module Main where
import System.Posix import System.CPUTime
printTime = getCPUTime >>= putStrLn . show
main = printTime >> sleep 5 >> printTime ---------
It produces this output: 1430000000000 1430000000000
or similar. In any case, both the numbers are the same. Should the second number not reflect a time 5 seconds later than the first? I've tried this with both GHC and Hugs, and both give me the same thing.
Thanks. Mike Benfield
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, 2005-11-21 at 15:14 -0500, Michael Benfield wrote:
I'm new to Haskell. I'm apparently misunderstanding something here.
When I run this program:
--------- module Main where
import System.Posix import System.CPUTime
printTime = getCPUTime >>= putStrLn . show
main = printTime >> sleep 5 >> printTime ---------
It produces this output: 1430000000000 1430000000000
or similar. In any case, both the numbers are the same. Should the second number not reflect a time 5 seconds later than the first? I've tried this with both GHC and Hugs, and both give me the same thing.
http://haskell.org/ghc/docs/latest/html/libraries/base/System-CPUTime.html getCPUTime :: IO Integer Computation getCPUTime returns the number of picoseconds CPU time used by the current program. The precision of this result is implementation-dependent. The key point there is that it is the CPU time *used* by the program. So sleeping uses no cpu time. Also, the precision is probably not terribly high which is why you get the exact same answer despite having used a minute about of actual cpu time. You can find the precision by using cpuTimePrecision. You probably want actual time rather than cpu time, in which case you should use the System.Time module. Duncan
participants (4)
-
Cale Gibbard
-
Duncan Coutts
-
Jon Fairbairn
-
Michael Benfield