GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tests/tools/test_matrix.cpp Lines: 19 19 100.0 %
Date: 2023-03-13 12:09:37 Branches: 21 32 65.6 %

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
2
  dynamicgraph::Matrix P(40, 40);
42
2
  dynamicgraph::Matrix J(6, 40);
43
1
  dynamicgraph::Matrix JK(6, 40);
44
41
  for (int i = 0; i < 40; ++i)
45

1640
    for (int j = 0; j < 40; ++j) P(i, j) = (rand() + 1.) / RAND_MAX;
46

7
  for (int i = 0; i < J.rows(); ++i)
47

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
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

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

1
  cout << dt / nbIter << endl;
63
64
  sotDEBUGOUT(15);
65
1
  return 0;
66
}