summaryrefslogtreecommitdiff
path: root/examples/speed.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-10-22 18:43:08 +0000
committerAlberto Ruiz <aruiz@um.es>2007-10-22 18:43:08 +0000
commit477c7cfc74c93363708ece4832947455c3e55e31 (patch)
tree1c0ea4836a41615058085ce465d84f122076e8f5 /examples/speed.hs
parent1a9c07dd1fffdbd7eb939fa6a781793419947c08 (diff)
speed tests
Diffstat (limited to 'examples/speed.hs')
-rw-r--r--examples/speed.hs50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/speed.hs b/examples/speed.hs
new file mode 100644
index 0000000..a937f31
--- /dev/null
+++ b/examples/speed.hs
@@ -0,0 +1,50 @@
1import Numeric.LinearAlgebra
2import System
3import Data.List(foldl1')
4import System.CPUTime
5import Text.Printf
6import Debug.Trace
7
8debug x = trace (show x) x
9
10timing act = do
11 t0 <- getCPUTime
12 act
13 t1 <- getCPUTime
14 printf "%.2f CPU seconds\n" $ (fromIntegral ((t1 - t0) `div` (10^10)) / 100 :: Double)
15
16op a b = trans $ (trans a) <> (trans b)
17
18op2 a b = trans $ (trans a) + (trans b)
19
20rot' :: Double -> Matrix Double
21rot' a = matrix [[ c,0,s],
22 [ 0,1,0],
23 [-s,0,c]]
24 where c = cos a
25 s = sin a
26 matrix = fromLists
27
28rot :: Double -> Matrix Double
29rot a = (3><3) [ c,0,s
30 , 0,1,0
31 ,-s,0,c ]
32 where c = cos a
33 s = sin a
34
35
36fun n r = foldl1' (<>) (map r [0,delta..1]) where delta = 1 /(fromIntegral n-1)
37
38
39main = do
40 args <- getArgs
41 let [p,n,d] = map read args
42 let ms = replicate n ((ident d :: Matrix Double))
43 let mz = replicate n (diag (constant (0::Double) d))
44 timing $ case p of
45 0 -> print $ foldl1' (<>) ms
46 1 -> print $ foldl1' (<>) (map trans ms)
47 2 -> print $ foldl1' op ms
48 3 -> print $ foldl1' op2 mz
49 4 -> print $ fun n rot'
50 5 -> print $ fun n rot