Skip to content

Commit 7994da9

Browse files
committed
A nanobenchmark for Hermite3.
1 parent 5d6d5c5 commit 7994da9

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include "geometry/frame.hpp"
2+
#include "geometry/grassmann.hpp"
3+
#include "geometry/instant.hpp"
4+
#include "geometry/space.hpp"
5+
#include "nanobenchmarks/nanobenchmark.hpp" // 🧙 For NANOBENCHMARK_*.
6+
#include "numerics/hermite3.hpp"
7+
#include "quantities/si.hpp"
8+
9+
namespace principia {
10+
namespace nanobenchmarks {
11+
12+
using namespace principia::geometry::_frame;
13+
using namespace principia::geometry::_grassmann;
14+
using namespace principia::geometry::_instant;
15+
using namespace principia::geometry::_space;
16+
using namespace principia::nanobenchmarks::_nanobenchmark;
17+
using namespace principia::numerics::_hermite3;
18+
using namespace principia::quantities::_si;
19+
20+
using World = Frame<serialization::Frame::TestTag,
21+
Inertial,
22+
Handedness::Right,
23+
serialization::Frame::TEST>;
24+
25+
class Hermite3Nanobenchmark : public Nanobenchmark {
26+
protected:
27+
using H = Hermite3<Displacement<World>, Instant>;
28+
29+
Hermite3Nanobenchmark()
30+
: t0_(Instant() + 0.3 * Second),
31+
t1_(Instant() + 3 * Second),
32+
d0_({0 * Metre, 0 * Metre, 1 * Metre}),
33+
d1_({1 * Metre, 3 * Metre, 1 * Metre}),
34+
v0_({0 * Metre / Second, 1 * Metre / Second, 0 * Metre / Second}),
35+
v1_({0 * Metre / Second, 3 * Metre / Second, 3 * Metre / Second}),
36+
h_({t0_, t1_}, {d0_, d1_}, {v0_, v1_}) {};
37+
38+
static double ToDouble(Displacement<World> const& displacement) {
39+
auto const& coordinates = displacement.coordinates();
40+
return _mm_cvtsd_f64(
41+
_mm_and_pd(_mm_set_pd(coordinates.x / Metre, coordinates.y / Metre),
42+
_mm_set_sd(coordinates.z / Metre)));
43+
}
44+
45+
static double ToDouble(Displacement<World> const& displacement,
46+
Velocity<World> const& velocity) {
47+
auto const& d = displacement.coordinates();
48+
auto const& v = velocity.coordinates();
49+
return _mm_cvtsd_f64(
50+
_mm_and_pd(_mm_and_pd(_mm_set_pd(d.x / Metre, d.y / Metre),
51+
_mm_set_pd(d.z / Metre, v.x / (Metre / Second))),
52+
_mm_set_pd(v.y / (Metre / Second), v.z / (Metre / Second))));
53+
}
54+
55+
Instant const t0_;
56+
Instant const t1_;
57+
Displacement<World> const d0_;
58+
Displacement<World> const d1_;
59+
Velocity<World> const v0_;
60+
Velocity<World> const v1_;
61+
H const h_;
62+
};
63+
64+
NANOBENCHMARK_FIXTURE(Hermite3Nanobenchmark, ConstructionAndValue) {
65+
H const h({t0_, t1_ + x * Second}, {d0_, d1_}, {v0_, v1_});
66+
return ToDouble(h.Evaluate(t0_));
67+
}
68+
69+
NANOBENCHMARK_FIXTURE(Hermite3Nanobenchmark, Value) {
70+
return ToDouble(h_.Evaluate(t0_ + x * Second));
71+
}
72+
73+
NANOBENCHMARK_FIXTURE(Hermite3Nanobenchmark, ValueAndDerivative) {
74+
Instant const t = t0_ + x * Second;
75+
return ToDouble(h_.Evaluate(t), h_.EvaluateDerivative(t));
76+
}
77+
78+
} // namespace nanobenchmarks
79+
} // namespace principia

nanobenchmarks/nanobenchmarks.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ClCompile Include="elementary_functions_nanobenchmark.cpp" />
1919
<ClCompile Include="examples_nanobenchmark.cpp" />
2020
<ClCompile Include="flag_parsing.cpp" />
21+
<ClCompile Include="hermite3_nanobenchmark.cpp" />
2122
<ClCompile Include="latency_distribution_table.cpp" />
2223
<ClCompile Include="main.cpp" />
2324
<ClCompile Include="nanobenchmark.cpp" />

nanobenchmarks/nanobenchmarks.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<ClCompile Include="nanobenchmark.cpp">
4343
<Filter>Source Files</Filter>
4444
</ClCompile>
45+
<ClCompile Include="hermite3_nanobenchmark.cpp">
46+
<Filter>Source Files</Filter>
47+
</ClCompile>
4548
</ItemGroup>
4649
<ItemGroup>
4750
<ClInclude Include="performance_settings_controller.hpp">

0 commit comments

Comments
 (0)