|
| 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 |
0 commit comments