summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/benchmarks.hs33
1 files changed, 19 insertions, 14 deletions
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs
index d19084a..517d402 100644
--- a/examples/benchmarks.hs
+++ b/examples/benchmarks.hs
@@ -1,4 +1,4 @@
1{-# OPTIONS -fbang-patterns #-} 1{-# LANGUAGE BangPatterns #-}
2 2
3-- compile as: 3-- compile as:
4-- ghc --make -O2 -optc-O2 -fvia-C benchmarks.hs 4-- ghc --make -O2 -optc-O2 -fvia-C benchmarks.hs
@@ -32,7 +32,7 @@ bench1 = do
32 time $ printf " Haskell: %.2f: " $ sumVH w 32 time $ printf " Haskell: %.2f: " $ sumVH w
33 time $ printf " BLAS: %.2f: " $ sumVB w 33 time $ printf " BLAS: %.2f: " $ sumVB w
34 time $ printf " Haskell: %.2f: " $ sumVH w 34 time $ printf " Haskell: %.2f: " $ sumVH w
35 --time $ printf " innerH: %.2f: " $ innerH w w2 35 time $ printf " innerH: %.2f: " $ innerH w w2
36 36
37sumVB v = constant 1 (dim v) <.> v 37sumVB v = constant 1 (dim v) <.> v
38 38
@@ -55,9 +55,9 @@ innerH u v = go (d - 1) 0
55bench2 = do 55bench2 = do
56 putStrLn "-------------------------------------------------------" 56 putStrLn "-------------------------------------------------------"
57 putStrLn "Multiplication of 1M different 3x3 matrices:" 57 putStrLn "Multiplication of 1M different 3x3 matrices:"
58-- putStrLn "from [[]]" 58-- putStrLn "from [[]]"
59-- time $ print $ fun (10^6) rot' 59-- time $ print $ manymult (10^6) rot'
60-- putStrLn "from []" 60-- putStrLn "from (3><3) []"
61 time $ print $ manymult (10^6) rot 61 time $ print $ manymult (10^6) rot
62 print $ cos (10^6/2) 62 print $ cos (10^6/2)
63 63
@@ -90,18 +90,18 @@ bench3 = do
90 putStrLn "foldVector" 90 putStrLn "foldVector"
91 let v = flatten $ ident 500 :: Vector Double 91 let v = flatten $ ident 500 :: Vector Double
92 print $ vectorMax v -- evaluate it 92 print $ vectorMax v -- evaluate it
93 let getPos k s = if k `mod` 500 < 200 && v@>k > 0 then k:s else s 93
94 putStrLn "indices extraction, dim=0.25M:"
95 time $ print $ (`divMod` 500) $ maximum $ foldLoop getPos [] (dim v)
96 putStrLn "sum, dim=30M:" 94 putStrLn "sum, dim=30M:"
97 --time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w) 95 -- time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w)
98 time $ print $ foldVector (\k v s -> v k + s) 0.0 w 96 time $ print $ sumVector w
97
99 putStrLn "sum, dim=0.25M:" 98 putStrLn "sum, dim=0.25M:"
100 --time $ print $ foldVector (\k v s -> v k + s) 0.0 v 99 --time $ print $ foldLoop (\k s -> v@>k + s) 0.0 (dim v)
101 time $ print $ foldLoop (\k s -> v@>k + s) 0.0 (dim v) 100 time $ print $ sumVector v
102 101
103-- foldVector is slower if it is used in two places. (!?) 102 let getPos k s = if k `mod` 500 < 200 && v@>k > 0 then k:s else s
104-- this does not happen with foldLoop 103 putStrLn "foldLoop for element selection, dim=0.25M:"
104 time $ print $ (`divMod` 500) $ maximum $ foldLoop getPos [] (dim v)
105 105
106foldLoop f s d = go (d - 1) s 106foldLoop f s d = go (d - 1) s
107 where 107 where
@@ -110,7 +110,12 @@ foldLoop f s d = go (d - 1) s
110 110
111foldVector f s v = foldLoop g s (dim v) 111foldVector f s v = foldLoop g s (dim v)
112 where g !k !s = f k (v@>) s 112 where g !k !s = f k (v@>) s
113 {-# INLINE g #-} -- Thanks Ryan Ingram (http://permalink.gmane.org/gmane.comp.lang.haskell.cafe/46479)
113 114
115sumVector = foldVector (\k v s -> v k + s) 0.0
116
117-- foldVector is slower if it is used in two places unles we use the above INLINE
118-- this does not happen with foldLoop
114-------------------------------------------------------------------------------- 119--------------------------------------------------------------------------------
115 120
116bench4 = do 121bench4 = do