diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/benchmarks.hs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs index 517d402..78c1e5f 100644 --- a/examples/benchmarks.hs +++ b/examples/benchmarks.hs | |||
@@ -1,8 +1,7 @@ | |||
1 | {-# LANGUAGE BangPatterns #-} | 1 | {-# LANGUAGE BangPatterns #-} |
2 | 2 | ||
3 | -- compile as: | 3 | -- $ ghc --make -O2 benchmarks.hs |
4 | -- ghc --make -O2 -optc-O2 -fvia-C benchmarks.hs | 4 | |
5 | -- ghc --make -O benchmarks.hs | ||
6 | 5 | ||
7 | import Numeric.LinearAlgebra | 6 | import Numeric.LinearAlgebra |
8 | import System.Time | 7 | import System.Time |
@@ -22,11 +21,11 @@ time act = do | |||
22 | main = sequence_ [bench1,bench2,bench3,bench4] | 21 | main = sequence_ [bench1,bench2,bench3,bench4] |
23 | 22 | ||
24 | w :: Vector Double | 23 | w :: Vector Double |
25 | w = constant 1 30000000 | 24 | w = constant 1 5000000 |
26 | w2 = 1 * w | 25 | w2 = 1 * w |
27 | 26 | ||
28 | bench1 = do | 27 | bench1 = do |
29 | putStrLn "Sum of a vector with 30M doubles:" | 28 | putStrLn "Sum of a vector with 5M doubles:" |
30 | print$ vectorMax (w+w2) -- evaluate it | 29 | print$ vectorMax (w+w2) -- evaluate it |
31 | time $ printf " BLAS: %.2f: " $ sumVB w | 30 | time $ printf " BLAS: %.2f: " $ sumVB w |
32 | time $ printf " Haskell: %.2f: " $ sumVH w | 31 | time $ printf " Haskell: %.2f: " $ sumVH w |
@@ -91,7 +90,7 @@ bench3 = do | |||
91 | let v = flatten $ ident 500 :: Vector Double | 90 | let v = flatten $ ident 500 :: Vector Double |
92 | print $ vectorMax v -- evaluate it | 91 | print $ vectorMax v -- evaluate it |
93 | 92 | ||
94 | putStrLn "sum, dim=30M:" | 93 | putStrLn "sum, dim=5M:" |
95 | -- time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w) | 94 | -- time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w) |
96 | time $ print $ sumVector w | 95 | time $ print $ sumVector w |
97 | 96 | ||
@@ -114,7 +113,7 @@ foldVector f s v = foldLoop g s (dim v) | |||
114 | 113 | ||
115 | sumVector = foldVector (\k v s -> v k + s) 0.0 | 114 | sumVector = foldVector (\k v s -> v k + s) 0.0 |
116 | 115 | ||
117 | -- foldVector is slower if it is used in two places unles we use the above INLINE | 116 | -- foldVector is slower if used in two places unless we use the above INLINE |
118 | -- this does not happen with foldLoop | 117 | -- this does not happen with foldLoop |
119 | -------------------------------------------------------------------------------- | 118 | -------------------------------------------------------------------------------- |
120 | 119 | ||