summaryrefslogtreecommitdiff
path: root/examples/experiments/speed.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2009-05-13 09:58:48 +0000
committerAlberto Ruiz <aruiz@um.es>2009-05-13 09:58:48 +0000
commit37f71ca5188ba487d4e1c274873b187ddcb30576 (patch)
treec752b450f8d5829d2eacbe94222aeab358ceb255 /examples/experiments/speed.hs
parent6809103cf34a9345f8cb60a0ec3a8f55dd18d5ef (diff)
removed old examples
Diffstat (limited to 'examples/experiments/speed.hs')
-rw-r--r--examples/experiments/speed.hs90
1 files changed, 0 insertions, 90 deletions
diff --git a/examples/experiments/speed.hs b/examples/experiments/speed.hs
deleted file mode 100644
index 22d7220..0000000
--- a/examples/experiments/speed.hs
+++ /dev/null
@@ -1,90 +0,0 @@
1{- speed tests
2
3GNU-Octave (see speed.m in this folder):
4
5./speed.m
6 -0.017877255967426 0.000000000000000 -0.999840189089781
7 0.000000000000000 1.000000000000000 0.000000000000000
8 0.999840189089763 0.000000000000000 -0.017877255967417
99.69 seconds
10
11Mathematica:
12
13rot[a_]:={{ Cos[a], 0, Sin[a]},
14 { 0, 1, 0},
15 { -Sin[a],0,Cos[a]}}//N
16
17test := Timing[
18 n = 100000;
19 angles = Range[0.,n-1]/(n-1);
20 Fold[Dot,IdentityMatrix[3],rot/@angles] // MatrixForm
21]
22
232.08013 Second
24 {{\(-0.017877255967432837`\), "0.`", \(-0.9998401890898042`\)},
25 {"0.`", "1.`", "0.`"},
26 {"0.9998401890898042`", "0.`", \(-0.017877255967432837`\)}}
27
28$ ghc --make -O speed
29
30$ ./speed 5 100000 1
31(3><3)
32 [ -1.7877255967425523e-2, 0.0, -0.9998401890897632
33 , 0.0, 1.0, 0.0
34 , 0.999840189089781, 0.0, -1.7877255967416586e-2 ]
350.33 CPU seconds
36
37cos 50000 = -0.0178772559665563
38sin 50000 = -0.999840189089790
39
40-}
41
42import Numeric.LinearAlgebra
43import System
44import Data.List(foldl1')
45import System.CPUTime
46import Text.Printf
47import Debug.Trace
48
49debug x = trace (show x) x
50
51timing act = do
52 t0 <- getCPUTime
53 act
54 t1 <- getCPUTime
55 printf "%.2f CPU seconds\n" $ (fromIntegral ((t1 - t0) `div` (10^10)) / 100 :: Double) :: IO ()
56
57op a b = trans $ (trans a) <> (trans b)
58
59op2 a b = trans $ (trans a) + (trans b)
60
61rot' :: Double -> Matrix Double
62rot' a = matrix [[ c,0,s],
63 [ 0,1,0],
64 [-s,0,c]]
65 where c = cos a
66 s = sin a
67 matrix = fromLists
68
69rot :: Double -> Matrix Double
70rot a = (3><3) [ c,0,s
71 , 0,1,0
72 ,-s,0,c ]
73 where c = cos a
74 s = sin a
75
76fun n r = foldl1' (<>) (map r angles)
77 where angles = toList $ linspace n (0,1)
78
79main = do
80 args <- getArgs
81 let [p,n,d] = map read args
82 let ms = replicate n ((ident d :: Matrix Double))
83 let mz = replicate n (diag (constant (0::Double) d))
84 timing $ case p of
85 0 -> print $ foldl1' (<>) ms
86 1 -> print $ foldl1' (<>) (map trans ms)
87 2 -> print $ foldl1' op ms
88 3 -> print $ foldl1' op2 mz
89 4 -> print $ fun n rot'
90 5 -> print $ fun n rot