blob: 612d428f0efaf852518e84a695eb00cf92e77b24 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
{-# LANGUAGE JavaScriptFFI #-}
module System.CPUTime.Javascript
( getCPUTime
, getCpuTimePrecision
)
where
import qualified System.CPUTime.Unsupported as I
getCpuTimePrecision :: IO Integer
getCpuTimePrecision = toInteger <$> js_cpuTimePrecision
getCPUTime :: IO Integer
getCPUTime = do
t <- js_getCPUTime
if t == -1 then I.getCPUTime
else pure (1000 * round t)
foreign import javascript unsafe
"(() => { return h$cpuTimePrecision(); })"
js_cpuTimePrecision :: IO Int
foreign import javascript unsafe
"(() => { return h$getCPUTime(); })"
js_getCPUTime :: IO Double
|