Last active
December 4, 2020 11:28
-
-
Save adamkewley/f249daa7d147d0b952bfc4233773e005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <OpenSim/Common/Mtx.h> | |
#include <OpenSim/Simulation/Wrap/WrapMath.h> | |
#define PICOBENCH_IMPLEMENT_WITH_MAIN | |
#include "picobench.hpp" | |
#include <random> | |
static std::minstd_rand rng{std::random_device{}()}; | |
static std::uniform_real_distribution<double> dist; | |
static auto generate_v = []{ return dist(rng); }; | |
template<typename C, size_t N = 3> | |
static void fill(C mat) { | |
for (size_t i = 0; i < N; ++i) { | |
for (size_t j = 0; j < N; ++j) { | |
double v = generate_v(); | |
mat[i][j] = v; | |
} | |
} | |
} | |
SimTK::Mat33 simtk_f(SimTK::Rotation const& r, SimTK::Mat33 const& mat); | |
static void benchmark_SimTK_oneAxisRotation(picobench::state& s) { | |
SimTK::Mat33 mat; | |
SimTK::Mat33 b; | |
double angle = generate_v(); | |
fill(mat); | |
SimTK::Rotation Rx; | |
Rx.setRotationFromAngleAboutX(angle); | |
picobench::scope sc{s}; | |
for (int i = 0; i < s.iterations(); ++i) { | |
simtk_f(Rx, mat); | |
} | |
} | |
PICOBENCH(benchmark_SimTK_oneAxisRotation); | |
static void benchmark_oneAxisRotation(picobench::state& s) { | |
double Rxc[3][3], matc[3][3], bc[3][3]; | |
double angle = generate_v(); | |
fill(matc); | |
OpenSim::WrapMath::Make3x3DirCosMatrix(angle, Rxc); | |
picobench::scope sc{s}; | |
for (int i = 0; i < s.iterations(); ++i) { | |
OpenSim::Mtx::Multiply(3, 3, 3, (double*)matc, (double*)Rxc, (double*)bc); | |
} | |
} | |
PICOBENCH(benchmark_oneAxisRotation); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Simbody.h> | |
SimTK::Mat33 simtk_f(SimTK::Rotation const& r, SimTK::Mat33 const& mat) { | |
return mat * ~r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment