GCC Code Coverage Report


Directory: ./
File: tests/tools/test_matrix.cpp
Date: 2024-08-13 12:13:25
Exec Total Coverage
Lines: 20 20 100.0%
Branches: 19 28 67.9%

Line Branch Exec Source
1 /*
2 * Copyright 2010,
3 * François Bleibel,
4 * Olivier Stasse,
5 *
6 * CNRS/AIST
7 *
8 */
9
10 /* -------------------------------------------------------------------------- */
11 /* --- INCLUDES ------------------------------------------------------------- */
12 /* -------------------------------------------------------------------------- */
13
14 #include <dynamic-graph/linear-algebra.h>
15
16 #include <iostream>
17 #include <sot/core/debug.hh>
18 #include <sot/core/feature-abstract.hh>
19 using namespace std;
20
21 #include <sot/core/sot.hh>
22
23 #ifndef WIN32
24 #include <sys/time.h>
25 #else /*WIN32*/
26 #include <sot/core/utils-windows.hh>
27 #endif /*WIN32*/
28
29 #define sotCHRONO1 \
30 gettimeofday(&t1, NULL); \
31 dt = ((t1.tv_sec - t0.tv_sec) * 1000. + \
32 (t1.tv_usec - t0.tv_usec + 0.) / 1000.); \
33 cout << "dt: " << dt
34
35 1 int main(int, char **) {
36 sotDEBUGIN(15);
37
38 struct timeval t0, t1;
39 double dt;
40
41
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dynamicgraph::Matrix P(40, 40);
42
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dynamicgraph::Matrix J(6, 40);
43
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 dynamicgraph::Matrix JK(6, 40);
44
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1 times.
41 for (int i = 0; i < 40; ++i)
45
3/4
✓ Branch 2 taken 1600 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1600 times.
✓ Branch 5 taken 40 times.
1640 for (int j = 0; j < 40; ++j) P(i, j) = (rand() + 1.) / RAND_MAX;
46
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 1 times.
7 for (int i = 0; i < J.rows(); ++i)
47
3/4
✓ Branch 2 taken 240 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 240 times.
✓ Branch 6 taken 6 times.
246 for (int j = 0; j < J.cols(); ++j) J(i, j) = (rand() + 1.) / RAND_MAX;
48
49 1 int nbIter = 100000;
50 1 dt = 0;
51 1 gettimeofday(&t0, NULL);
52
2/2
✓ Branch 0 taken 100000 times.
✓ Branch 1 taken 1 times.
100001 for (int iter = 0; iter < nbIter; ++iter) {
53 100000 gettimeofday(&t0, NULL);
54 // J.multiply(P,JK);
55 // prod(J.matrix,P.matrix,JK.matrix);
56
2/4
✓ Branch 1 taken 100000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100000 times.
✗ Branch 5 not taken.
100000 JK = J * P;
57 100000 gettimeofday(&t1, NULL);
58 100000 dt += ((double)(t1.tv_sec - t0.tv_sec) +
59 100000 (double)(t1.tv_usec - t0.tv_usec) / 1000. / 1000.);
60 }
61 // sotCHRONO1 <<endl;
62
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 cout << dt / nbIter << endl;
63
64 sotDEBUGOUT(15);
65 1 return 0;
66 1 }
67