Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
3df660ad
Commit
3df660ad
authored
9 years ago
by
Joan Solà Ortega
Browse files
Options
Downloads
Patches
Plain Diff
Improve matrix product benchmark
parent
e832f22b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/examples/test_matrix_prod.cpp
+67
-335
67 additions, 335 deletions
src/examples/test_matrix_prod.cpp
with
67 additions
and
335 deletions
src/examples/test_matrix_prod.cpp
+
67
−
335
View file @
3df660ad
...
@@ -10,6 +10,50 @@
...
@@ -10,6 +10,50 @@
//std includes
//std includes
#include
<ctime>
#include
<ctime>
#include
<iostream>
#include
<iostream>
#include
<iomanip>
#define INIT_ALL\
R1.setRandom(s, s);\
R2.setRandom(s, s);\
C1.setRandom(s, s);\
C2.setRandom(s, s);
#define LOOP(N,Mo,M1,M2) \
for (int i = 0; i < N; i++) \
{ \
Mo = M1 * M2; \
M1(2,2) += 0.000001; \
M2(0,0) *= 1.000001; \
/*M2 = Mo; */
\
}
#define EVALUATE(N,Mo,M1,M2) \
t0 = clock(); \
LOOP(N,Mo,M1,M2) \
t1 = clock(); \
std::cout << std::setw(15) << Mo(2,2) << "\t";
#define EVALUATE_ALL \
EVALUATE(N, Ro, R1, R2)\
std::cout << "Time Ro = R * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\
EVALUATE(N, Ro, R1, C2)\
std::cout << "Time Ro = R * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\
EVALUATE(N, Ro, C1, R2)\
std::cout << "Time Ro = C * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\
EVALUATE(N, Ro, C1, C2)\
std::cout << "Time Ro = C * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\
EVALUATE(N, Co, R1, R2)\
std::cout << "Time Co = R * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\
EVALUATE(N, Co, R1, C2)\
std::cout << "Time Co = R * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\
EVALUATE(N, Co, C1, R2)\
std::cout << "Time Co = C * R: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N << "ns" << std::endl;\
EVALUATE(N, Co, C1, C2)\
std::cout << "Time Co = C * C: " << (long double)(t1 - t0) * 1e9 / CLOCKS_PER_SEC / N \
<< "us <-- this is the Eigen default!" << std::endl;
/**
/**
* We multiply matrices and see how long it takes.
* We multiply matrices and see how long it takes.
...
@@ -20,10 +64,10 @@ int main()
...
@@ -20,10 +64,10 @@ int main()
{
{
using
namespace
Eigen
;
using
namespace
Eigen
;
int
N
=
100000
0
;
int
N
=
100000
;
const
int
S
=
6
;
const
int
S
=
6
;
Matrix
<
double
,
16
,
S
-
3
+
1
>
results
;
Matrix
<
double
,
16
,
S
-
3
+
1
>
results
;
clock_t
t0
;
clock_t
t0
,
t1
;
{
{
Matrix
<
double
,
Dynamic
,
Dynamic
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
Dynamic
,
Dynamic
,
RowMajor
>
R1
,
R2
,
Ro
;
...
@@ -31,152 +75,24 @@ int main()
...
@@ -31,152 +75,24 @@ int main()
for
(
int
s
=
3
;
s
<=
S
;
s
++
)
for
(
int
s
=
3
;
s
<=
S
;
s
++
)
{
{
R1
.
setRandom
(
s
,
s
);
R2
.
setRandom
(
s
,
s
);
C1
.
setRandom
(
s
,
s
);
C2
.
setRandom
(
s
,
s
);
std
::
cout
<<
"Timings for dynamic matrix product. R: row major matrix. C: column major matrix. "
<<
s
<<
"x"
std
::
cout
<<
"Timings for dynamic matrix product. R: row major matrix. C: column major matrix. "
<<
s
<<
"x"
<<
s
<<
" matrices."
<<
std
::
endl
;
<<
s
<<
" matrices."
<<
std
::
endl
;
t0
=
clock
();
INIT_ALL
for
(
int
i
=
0
;
i
<
N
;
i
++
)
EVALUATE_ALL
{
Ro
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us <-- this is the Eigen default!"
<<
std
::
endl
;
}
}
}
}
N
*=
10
;
//
N *= 10
00
;
{
{
const
int
s
=
3
;
const
int
s
=
3
;
std
::
cout
<<
"Timings for static matrix product. R: row major matrix. C: column major matrix. "
<<
s
<<
"x"
<<
s
std
::
cout
<<
"Timings for static matrix product. R: row major matrix. C: column major matrix. "
<<
s
<<
"x"
<<
s
<<
" matrices."
<<
std
::
endl
;
<<
" matrices."
<<
std
::
endl
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
INIT_ALL
for
(
int
i
=
0
;
i
<
N
;
i
++
)
EVALUATE_ALL
{
Co
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us <-- this is the Eigen default!"
<<
std
::
endl
;
}
}
{
{
const
int
s
=
4
;
const
int
s
=
4
;
...
@@ -184,141 +100,20 @@ int main()
...
@@ -184,141 +100,20 @@ int main()
<<
" matrices."
<<
std
::
endl
;
<<
" matrices."
<<
std
::
endl
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
INIT_ALL
for
(
int
i
=
0
;
i
<
N
;
i
++
)
EVALUATE_ALL
{
Co
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us <-- this is the Eigen default!"
<<
std
::
endl
;
}
}
// N /= 100000;
{
{
const
int
s
=
5
;
const
int
s
=
5
;
std
::
cout
<<
"Timings for static matrix product. R: row major matrix. C: column major matrix. "
<<
s
<<
"x"
<<
s
std
::
cout
<<
"Timings for static matrix product. R: row major matrix. C: column major matrix. "
<<
s
<<
"x"
<<
s
<<
" matrices."
<<
std
::
endl
;
<<
" matrices."
<<
std
::
endl
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
INIT_ALL
for
(
int
i
=
0
;
i
<
N
;
i
++
)
EVALUATE_ALL
{
Ro
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us <-- this is the Eigen default!"
<<
std
::
endl
;
}
}
{
{
const
int
s
=
6
;
const
int
s
=
6
;
...
@@ -326,97 +121,34 @@ int main()
...
@@ -326,97 +121,34 @@ int main()
<<
" matrices."
<<
std
::
endl
;
<<
" matrices."
<<
std
::
endl
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
RowMajor
>
R1
,
R2
,
Ro
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
Matrix
<
double
,
s
,
s
,
ColMajor
>
C1
,
C2
,
Co
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
INIT_ALL
for
(
int
i
=
0
;
i
<
N
;
i
++
)
EVALUATE_ALL
{
Ro
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Ro
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"TimeRo = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
R1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = R * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
R2
;
R2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * R: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Co
=
C1
*
C2
;
C2
.
setRandom
();
}
std
::
cout
<<
"Time Co = C * C: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us <-- this is the Eigen default!"
<<
std
::
endl
;
}
}
std
::
cout
<<
"Test q and R rotations"
<<
std
::
endl
;
std
::
cout
<<
"Test q and R rotations"
<<
std
::
endl
;
Eigen
::
Quaterniond
q
(
Eigen
::
Vector4d
::
Random
().
normalized
());
Eigen
::
Quaterniond
q
(
Eigen
::
Vector4d
::
Random
().
normalized
());
Eigen
::
Matrix3d
R
=
q
.
matrix
();
Eigen
::
Matrix3d
R
=
q
.
matrix
();
Eigen
::
Vector3d
v
((
Eigen
::
Vector3d
()
<<
1
,
2
,
3
).
finished
());
Eigen
::
Vector3d
v
;
v
<<
1
,
2
,
3
;
double
vn
=
v
.
norm
();
Eigen
::
Vector3d
w
;
N
*=
10
;
N
*=
10
0
;
t0
=
clock
();
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
{
w
=
R
*
v
;
v
=
R
*
v
;
v
.
setRandom
();
}
}
t1
=
clock
();
std
::
cout
<<
"Time w = R * v: "
<<
(
(
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"
u
s"
<<
std
::
endl
;
std
::
cout
<<
"Time w = R * v: "
<<
(
double
)
(
t1
-
t0
)
*
1e9
/
CLOCKS_PER_SEC
/
N
<<
"
n
s"
<<
std
::
endl
;
t0
=
clock
();
t0
=
clock
();
for
(
int
i
=
0
;
i
<
N
;
i
++
)
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
{
w
=
q
*
v
;
v
=
q
*
v
;
v
.
setRandom
();
}
}
std
::
cout
<<
"Time w = q * v: "
<<
((
double
)
clock
()
-
t0
)
/
CLOCKS_PER_SEC
/
N
*
1e6
<<
"us"
<<
std
::
endl
;
t1
=
clock
();
std
::
cout
<<
"Time w = q * v: "
<<
(
double
)(
t1
-
t0
)
*
1e9
/
CLOCKS_PER_SEC
/
N
<<
"ns"
<<
std
::
endl
;
std
::
cout
<<
"v norm change: "
<<
10
*
log
((
long
double
)
v
.
norm
()
/
(
long
double
)
vn
)
<<
" dB"
<<
std
::
endl
;
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment