summaryrefslogtreecommitdiff
path: root/examples/benchmarks.hs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/benchmarks.hs')
-rw-r--r--examples/benchmarks.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs
index 073a95d..d19084a 100644
--- a/examples/benchmarks.hs
+++ b/examples/benchmarks.hs
@@ -19,18 +19,20 @@ time act = do
19 19
20-------------------------------------------------------------------------------- 20--------------------------------------------------------------------------------
21 21
22main = sequence_ [bench1,bench2,bench3] 22main = sequence_ [bench1,bench2,bench3,bench4]
23 23
24w :: Vector Double 24w :: Vector Double
25w = constant 1 30000000 25w = constant 1 30000000
26w2 = 1 * w
26 27
27bench1 = do 28bench1 = do
28 putStrLn "Sum of a vector with 30M doubles:" 29 putStrLn "Sum of a vector with 30M doubles:"
29 print$ vectorMax w -- evaluate it 30 print$ vectorMax (w+w2) -- evaluate it
30 time $ printf " BLAS: %.2f: " $ sumVB w 31 time $ printf " BLAS: %.2f: " $ sumVB w
31 time $ printf " Haskell: %.2f: " $ sumVH w 32 time $ printf " Haskell: %.2f: " $ sumVH w
32 time $ printf " BLAS: %.2f: " $ sumVB w 33 time $ printf " BLAS: %.2f: " $ sumVB w
33 time $ printf " Haskell: %.2f: " $ sumVH w 34 time $ printf " Haskell: %.2f: " $ sumVH w
35 --time $ printf " innerH: %.2f: " $ innerH w w2
34 36
35sumVB v = constant 1 (dim v) <.> v 37sumVB v = constant 1 (dim v) <.> v
36 38
@@ -41,6 +43,13 @@ sumVH v = go (d - 1) 0
41 go 0 s = s + (v @> 0) 43 go 0 s = s + (v @> 0)
42 go !j !s = go (j - 1) (s + (v @> j)) 44 go !j !s = go (j - 1) (s + (v @> j))
43 45
46innerH u v = go (d - 1) 0
47 where
48 d = dim u
49 go :: Int -> Double -> Double
50 go 0 s = s + (u @> 0) * (v @> 0)
51 go !j !s = go (j - 1) (s + (u @> j) * (v @> j))
52
44-------------------------------------------------------------------------------- 53--------------------------------------------------------------------------------
45 54
46bench2 = do 55bench2 = do
@@ -101,3 +110,13 @@ foldLoop f s d = go (d - 1) s
101 110
102foldVector f s v = foldLoop g s (dim v) 111foldVector f s v = foldLoop g s (dim v)
103 where g !k !s = f k (v@>) s 112 where g !k !s = f k (v@>) s
113
114--------------------------------------------------------------------------------
115
116bench4 = do
117 putStrLn "-------------------------------------------------------"
118 putStrLn "1000x1000 inverse"
119 let a = ident 1000 :: Matrix Double
120 let b = 2*a
121 print $ vectorMax $ flatten (a+b) -- evaluate it
122 time $ print $ vectorMax $ flatten $ linearSolve a b