summaryrefslogtreecommitdiff
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
parent1a9c07dd1fffdbd7eb939fa6a781793419947c08 (diff)
speed tests
-rw-r--r--examples/data.txt20
-rw-r--r--examples/speed.hs50
-rw-r--r--examples/speed.m20
-rw-r--r--hssl.cabal (renamed from HSSL.cabal)0
4 files changed, 80 insertions, 10 deletions
diff --git a/examples/data.txt b/examples/data.txt
index 7031462..2b9bfea 100644
--- a/examples/data.txt
+++ b/examples/data.txt
@@ -1,10 +1,10 @@
1 1 1.1 1 0.9 1.1
2 2 3.9 2 2.1 3.9
3 3 9.2 3 3.1 9.2
4 4 15.8 4 4.0 51.8
5 5 25.3 5 4.9 25.3
6 6 35.7 6 6.1 35.7
7 7 49.4 7 7.0 49.4
8 8 63.6 8 7.9 3.6
9 9 81.5 9 9.1 81.5
1010 99.5 \ No newline at end of file 1010.2 99.5 \ No newline at end of file
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
diff --git a/examples/speed.m b/examples/speed.m
new file mode 100644
index 0000000..10dbf78
--- /dev/null
+++ b/examples/speed.m
@@ -0,0 +1,20 @@
1#! /usr/bin/octave -qf
21; % measuring Octave computing times
3
4function r = rot(a)
5 c = cos(a);
6 s = sin(a);
7 r = [ c , 0, s;
8 0, 1, 0;
9 -s, 0, c];
10end
11
12t0=time();
13x = linspace(0,1,1E5);
14ac = eye(3);
15for a=x
16 ac = rot(a)*ac;
17end
18
19disp(ac);
20disp(time()-t0)
diff --git a/HSSL.cabal b/hssl.cabal
index 6905a6a..6905a6a 100644
--- a/HSSL.cabal
+++ b/hssl.cabal