-
Notifications
You must be signed in to change notification settings - Fork 104
/
rpar.hs
59 lines (52 loc) · 933 Bytes
/
rpar.hs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import Control.Parallel
import Control.Parallel.Strategies
import Control.Exception
import Data.Time.Clock
import Text.Printf
import System.Environment
-- <<fib
fib :: Integer -> Integer
fib 0 = 1
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
-- >>
-- <<main
main = do
[n] <- getArgs
let test = [test1,test2,test3,test4] !! (read n - 1)
t0 <- getCurrentTime
r <- evaluate (runEval test)
printTimeSince t0
print r
printTimeSince t0
-- >>
-- <<test1
test1 = do
x <- rpar (fib 36)
y <- rpar (fib 35)
return (x,y)
-- >>
-- <<test2
test2 = do
x <- rpar (fib 36)
y <- rseq (fib 35)
return (x,y)
-- >>
-- <<test3
test3 = do
x <- rpar (fib 36)
y <- rseq (fib 35)
rseq x
return (x,y)
-- >>
-- <<test4
test4 = do
x <- rpar (fib 36)
y <- rpar (fib 35)
rseq x
rseq y
return (x,y)
-- >>
printTimeSince t0 = do
t1 <- getCurrentTime
printf "time: %.2fs\n" (realToFrac (diffUTCTime t1 t0) :: Double)