diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-10-22 18:43:08 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-10-22 18:43:08 +0000 |
commit | 477c7cfc74c93363708ece4832947455c3e55e31 (patch) | |
tree | 1c0ea4836a41615058085ce465d84f122076e8f5 | |
parent | 1a9c07dd1fffdbd7eb939fa6a781793419947c08 (diff) |
speed tests
-rw-r--r-- | examples/data.txt | 20 | ||||
-rw-r--r-- | examples/speed.hs | 50 | ||||
-rw-r--r-- | examples/speed.m | 20 | ||||
-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 |
10 | 10 99.5 \ No newline at end of file | 10 | 10.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 @@ | |||
1 | import Numeric.LinearAlgebra | ||
2 | import System | ||
3 | import Data.List(foldl1') | ||
4 | import System.CPUTime | ||
5 | import Text.Printf | ||
6 | import Debug.Trace | ||
7 | |||
8 | debug x = trace (show x) x | ||
9 | |||
10 | timing 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 | |||
16 | op a b = trans $ (trans a) <> (trans b) | ||
17 | |||
18 | op2 a b = trans $ (trans a) + (trans b) | ||
19 | |||
20 | rot' :: Double -> Matrix Double | ||
21 | rot' 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 | |||
28 | rot :: Double -> Matrix Double | ||
29 | rot 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 | |||
36 | fun n r = foldl1' (<>) (map r [0,delta..1]) where delta = 1 /(fromIntegral n-1) | ||
37 | |||
38 | |||
39 | main = 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 | ||
2 | 1; % measuring Octave computing times | ||
3 | |||
4 | function r = rot(a) | ||
5 | c = cos(a); | ||
6 | s = sin(a); | ||
7 | r = [ c , 0, s; | ||
8 | 0, 1, 0; | ||
9 | -s, 0, c]; | ||
10 | end | ||
11 | |||
12 | t0=time(); | ||
13 | x = linspace(0,1,1E5); | ||
14 | ac = eye(3); | ||
15 | for a=x | ||
16 | ac = rot(a)*ac; | ||
17 | end | ||
18 | |||
19 | disp(ac); | ||
20 | disp(time()-t0) | ||