summaryrefslogtreecommitdiff
path: root/examples/speed.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2007-10-29 18:21:06 +0000
committerAlberto Ruiz <aruiz@um.es>2007-10-29 18:21:06 +0000
commit2facdf74f267ff81645336528a50696f61bb8670 (patch)
treedd5049c2d0cb1b1c4cd919af77a305b9025fe8dd /examples/speed.hs
parentfd73d3eb9d671bd5be23024d4cc5eeb7b5fdeb58 (diff)
fixed terrible toList bug
Diffstat (limited to 'examples/speed.hs')
-rw-r--r--examples/speed.hs46
1 files changed, 33 insertions, 13 deletions
diff --git a/examples/speed.hs b/examples/speed.hs
index 865e3e1..22d7220 100644
--- a/examples/speed.hs
+++ b/examples/speed.hs
@@ -1,21 +1,42 @@
1{- speed tests 1{- speed tests
2 2
3$ ghc --make -O speed 3GNU-Octave (see speed.m in this folder):
4In my machine:
5$ ./speed 5 100000 1
6(3><3)
7 [ -1.7877285611885504e-2, 0.0, -0.9998401885597121
8 , 0.0, 1.0, 0.0
9 , 0.9998401885597168, 0.0, -1.7877285611891697e-2 ]
100.29 CPU seconds
11 4
12GNU-Octave:
13./speed.m 5./speed.m
14 -0.017877255967426 0.000000000000000 -0.999840189089781 6 -0.017877255967426 0.000000000000000 -0.999840189089781
15 0.000000000000000 1.000000000000000 0.000000000000000 7 0.000000000000000 1.000000000000000 0.000000000000000
16 0.999840189089763 0.000000000000000 -0.017877255967417 8 0.999840189089763 0.000000000000000 -0.017877255967417
179.69 seconds 99.69 seconds
18 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
19-} 40-}
20 41
21import Numeric.LinearAlgebra 42import Numeric.LinearAlgebra
@@ -31,7 +52,7 @@ timing act = do
31 t0 <- getCPUTime 52 t0 <- getCPUTime
32 act 53 act
33 t1 <- getCPUTime 54 t1 <- getCPUTime
34 printf "%.2f CPU seconds\n" $ (fromIntegral ((t1 - t0) `div` (10^10)) / 100 :: Double) 55 printf "%.2f CPU seconds\n" $ (fromIntegral ((t1 - t0) `div` (10^10)) / 100 :: Double) :: IO ()
35 56
36op a b = trans $ (trans a) <> (trans b) 57op a b = trans $ (trans a) <> (trans b)
37 58
@@ -52,9 +73,8 @@ rot a = (3><3) [ c,0,s
52 where c = cos a 73 where c = cos a
53 s = sin a 74 s = sin a
54 75
55 76fun n r = foldl1' (<>) (map r angles)
56fun n r = foldl1' (<>) (map r [0,delta..1]) where delta = 1 /(fromIntegral n-1) 77 where angles = toList $ linspace n (0,1)
57
58 78
59main = do 79main = do
60 args <- getArgs 80 args <- getArgs