diff options
Diffstat (limited to 'examples/benchmarks.hs')
-rw-r--r-- | examples/benchmarks.hs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/examples/benchmarks.hs b/examples/benchmarks.hs index 398d1ce..073a95d 100644 --- a/examples/benchmarks.hs +++ b/examples/benchmarks.hs | |||
@@ -70,20 +70,34 @@ rot a = (3><3) [ c,0,s | |||
70 | 70 | ||
71 | manymult n r = foldl1' (<>) (map r angles) | 71 | manymult n r = foldl1' (<>) (map r angles) |
72 | where angles = toList $ linspace n (0,1) | 72 | where angles = toList $ linspace n (0,1) |
73 | -- angles = map (k*) [0..n'] | ||
74 | -- n' = fromIntegral n - 1 | ||
75 | -- k = recip n' | ||
73 | 76 | ||
74 | -------------------------------------------------------------------------------- | 77 | -------------------------------------------------------------------------------- |
75 | 78 | ||
76 | bench3 = do | 79 | bench3 = do |
77 | putStrLn "-------------------------------------------------------" | 80 | putStrLn "-------------------------------------------------------" |
78 | putStrLn "foldVector:" | 81 | putStrLn "foldVector" |
79 | let v = flatten $ ident 555 :: Vector Double | 82 | let v = flatten $ ident 500 :: Vector Double |
80 | print $ vectorMax v -- evaluate it | 83 | print $ vectorMax v -- evaluate it |
81 | let getPos k s = if k `rem` 555 < 200 && v@>k > 0 then k:s else s | 84 | let getPos k s = if k `mod` 500 < 200 && v@>k > 0 then k:s else s |
82 | time $ print $ sum $ foldVector getPos [] v | 85 | putStrLn "indices extraction, dim=0.25M:" |
83 | time $ print $ foldVector (\k s -> w@>k + s) 0.0 w | 86 | time $ print $ (`divMod` 500) $ maximum $ foldLoop getPos [] (dim v) |
84 | 87 | putStrLn "sum, dim=30M:" | |
85 | foldVector f s v = go (d - 1) s | 88 | --time $ print $ foldLoop (\k s -> w@>k + s) 0.0 (dim w) |
89 | time $ print $ foldVector (\k v s -> v k + s) 0.0 w | ||
90 | putStrLn "sum, dim=0.25M:" | ||
91 | --time $ print $ foldVector (\k v s -> v k + s) 0.0 v | ||
92 | time $ print $ foldLoop (\k s -> v@>k + s) 0.0 (dim v) | ||
93 | |||
94 | -- foldVector is slower if it is used in two places. (!?) | ||
95 | -- this does not happen with foldLoop | ||
96 | |||
97 | foldLoop f s d = go (d - 1) s | ||
86 | where | 98 | where |
87 | d = dim v | ||
88 | go 0 s = f (0::Int) s | 99 | go 0 s = f (0::Int) s |
89 | go !j !s = go (j - 1) (f j s) | 100 | go !j !s = go (j - 1) (f j s) |
101 | |||
102 | foldVector f s v = foldLoop g s (dim v) | ||
103 | where g !k !s = f k (v@>) s | ||