FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
EigenLab/SpeedTestEigenLabVsMuParser.cpp at master · leggedrobotics/EigenLab · GitHub
leggedrobotics
/
EigenLab
Public
forked from
marcel-goldschen-ohm/EigenLab
Notifications
You must be signed in to change notification settings
Fork
2
Star
3
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
EigenLab
/
SpeedTestEigenLabVsMuParser.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
122 lines (115 loc) · 4.08 KB
Breadcrumbs
EigenLab
/
SpeedTestEigenLabVsMuParser.cpp
Copy path
File metadata and controls
122 lines (115 loc) · 4.08 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
----------------------------------------
//
EigenLab Speed Test
//
Author: Dr. Marcel Paz Goldschen-Ohm (based on scripts by Ilja Honkonen <ilja.j.honkonen@nasa.gov>)
//
Email: marcel.goldschen@gmail.com
//
Copyright (c) 2014 by Dr. Marcel Paz Goldschen-Ohm.
//
Licence: MIT
//
----------------------------------------
#
include
"
EigenLab.h
"
#
include
"
mpParser.h
"
#
include
<
array
>
#
include
<
chrono
>
#
include
<
iostream
>
#
include
<
vector
>
#
ifndef
EIGEN_NDEBUG
#
define
EIGEN_NDEBUG
#
endif
int
main
(
int
argc,
const
char
* argv[])
{
//
Test muParser.
//
Evaluate "i+1" one million times.
{
mup::ParserX parser;
//
(mup::pckCOMMON | mup::pckNON_COMPLEX | mup::pckMATRIX | mup::pckUNIT);
mup::Value value1{
0
};
mup::Variable variable1{& value1};
parser.
DefineVar
(
"
v1
"
, variable1);
parser.
SetExpr
(
"
v1 + 1
"
);
const
auto
timeStart =
std::chrono::high_resolution_clock::now
();
for
(
int
i =
0
; i <
1000000
; i++) {
value1 = i;
if
(parser.
Eval
().
GetInteger
() != i +
1
) {
std::cerr << __FILE__ <<
"
(
"
<< __LINE__<<
"
)
"
<<
"
Wrong value for variable:
"
<< parser.
Eval
().
GetInteger
()
<<
"
, should be:
"
<< i +
1
<< std::endl;
abort
();
}
}
const
auto
timeEnd =
std::chrono::high_resolution_clock::now
();
const
auto
total = std::chrono::duration_cast<std::chrono::duration<
double
> >(timeEnd - timeStart).
count
();
std::cout <<
"
1e6 evaluations of `i+1` took muParserX (s):
"
<< total << std::endl;
}
//
Test EigenLab.
//
Evaluate "i+1" one million times with expression caching off.
{
EigenLab::ParserXd parser;
double
variable1;
parser.
var
(
"
v1
"
).
setShared
(& variable1);
EigenLab::ValueXd result;
parser.
setCacheExpressions
(
false
);
const
auto
timeStart =
std::chrono::high_resolution_clock::now
();
for
(
int
i =
0
; i <
1000000
; i++) {
variable1 = i;
result = parser.
eval
(
"
v1 + 1
"
);
if
(result.
matrix
()(
0
,
0
) != i +
1
) {
std::cerr << __FILE__ <<
"
(
"
<< __LINE__<<
"
)
"
<<
"
Wrong value for variable:
"
<< result.
matrix
()(
0
,
0
)
<<
"
, should be:
"
<< i +
1
<< std::endl;
abort
();
}
}
const
auto
timeEnd =
std::chrono::high_resolution_clock::now
();
const
auto
total = std::chrono::duration_cast<std::chrono::duration<
double
> >(timeEnd - timeStart).
count
();
std::cout <<
"
1e6 evaluations of `i+1` (expression caching off) took EigenLab (s):
"
<< total << std::endl;
}
//
Test EigenLab.
//
Evaluate "i+1" one million times with expression caching on.
{
EigenLab::ParserXd parser;
double
variable1;
parser.
var
(
"
v1
"
).
setShared
(& variable1);
EigenLab::ValueXd result;
parser.
setCacheExpressions
(
true
);
const
auto
timeStart =
std::chrono::high_resolution_clock::now
();
for
(
int
i =
0
; i <
1000000
; i++) {
variable1 = i;
result = parser.
eval
(
"
v1 + 1
"
);
if
(result.
matrix
()(
0
,
0
) != i +
1
) {
std::cerr << __FILE__ <<
"
(
"
<< __LINE__<<
"
)
"
<<
"
Wrong value for variable:
"
<< result.
matrix
()(
0
,
0
)
<<
"
, should be:
"
<< i +
1
<< std::endl;
abort
();
}
}
const
auto
timeEnd =
std::chrono::high_resolution_clock::now
();
const
auto
total = std::chrono::duration_cast<std::chrono::duration<
double
> >(timeEnd - timeStart).
count
();
std::cout <<
"
1e6 evaluations of `i+1` (expression caching on) took EigenLab (s):
"
<< total << std::endl;
}
//
Test EigenLab.
//
Evaluate "i+1" on an array of one million values.
{
EigenLab::ParserXd parser;
const
auto
timeStart =
std::chrono::high_resolution_clock::now
();
Eigen::MatrixXd
variable1
(
1
,
1000000
);
parser.
var
(
"
v1
"
).
setShared
(variable1);
for
(
int
i =
0
; i <
1000000
; i++) {
variable1
(
0
, i) = i;
}
parser.
eval
(
"
v1 = v1 + 1
"
);
for
(
int
i =
0
; i <
1000000
; i++) {
if
(
variable1
(i) != i +
1
) {
std::cerr << __FILE__ <<
"
(
"
<< __LINE__<<
"
)
"
<<
"
Wrong value for variable:
"
<<
variable1
(i)
<<
"
, should be:
"
<< i +
1
<< std::endl;
abort
();
}
}
const
auto
timeEnd =
std::chrono::high_resolution_clock::now
();
const
auto
total = std::chrono::duration_cast<std::chrono::duration<
double
> >(timeEnd - timeStart).
count
();
std::cout <<
"
Creation of array i=[0:1e6-1] and evaluation of `i+1` took EigenLab (s):
"
<< total << std::endl;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL