summaryrefslogtreecommitdiff
path: root/examples/benchmarks.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2008-06-19 17:23:54 +0000
committerAlberto Ruiz <aruiz@um.es>2008-06-19 17:23:54 +0000
commit8dce18602825da9914832114283748244fa9b859 (patch)
tree7eb665a625b59fa405d1e6904a7b95d7e715ec46 /examples/benchmarks.hs
parent3aba203e0c686039bc8c872ef6beb3843537a48a (diff)
foldVector benchmark
Diffstat (limited to 'examples/benchmarks.hs')
-rw-r--r--examples/benchmarks.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs
index 0859d8f..398d1ce 100644
--- a/examples/benchmarks.hs
+++ b/examples/benchmarks.hs
@@ -19,7 +19,7 @@ time act = do
19 19
20-------------------------------------------------------------------------------- 20--------------------------------------------------------------------------------
21 21
22main = sequence_ [bench1,bench2] 22main = sequence_ [bench1,bench2,bench3]
23 23
24w :: Vector Double 24w :: Vector Double
25w = constant 1 30000000 25w = constant 1 30000000
@@ -70,3 +70,20 @@ rot a = (3><3) [ c,0,s
70 70
71manymult n r = foldl1' (<>) (map r angles) 71manymult n r = foldl1' (<>) (map r angles)
72 where angles = toList $ linspace n (0,1) 72 where angles = toList $ linspace n (0,1)
73
74--------------------------------------------------------------------------------
75
76bench3 = do
77 putStrLn "-------------------------------------------------------"
78 putStrLn "foldVector:"
79 let v = flatten $ ident 555 :: Vector Double
80 print $ vectorMax v -- evaluate it
81 let getPos k s = if k `rem` 555 < 200 && v@>k > 0 then k:s else s
82 time $ print $ sum $ foldVector getPos [] v
83 time $ print $ foldVector (\k s -> w@>k + s) 0.0 w
84
85foldVector f s v = go (d - 1) s
86 where
87 d = dim v
88 go 0 s = f (0::Int) s
89 go !j !s = go (j - 1) (f j s)