summaryrefslogtreecommitdiff
path: root/examples/benchmarks.hs
diff options
context:
space:
mode:
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)