Skip to content

Instantly share code, notes, and snippets.

@adamkewley
Last active December 4, 2020 11:28
Show Gist options
  • Save adamkewley/f249daa7d147d0b952bfc4233773e005 to your computer and use it in GitHub Desktop.
Save adamkewley/f249daa7d147d0b952bfc4233773e005 to your computer and use it in GitHub Desktop.
#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);

Name (baseline is *) | Dim | Total ms | ns/op |Baseline| Ops/second

benchmark_SimTK_oneAxisRotation * | 8 | 0.000 | 32 | - | 30769230.8 benchmark_oneAxisRotation | 8 | 0.001 | 80 | 2.469 | 12461059.2 benchmark_SimTK_oneAxisRotation * | 64 | 0.002 | 25 | - | 39925140.4 benchmark_oneAxisRotation | 64 | 0.004 | 65 | 2.606 | 15318334.1 benchmark_SimTK_oneAxisRotation * | 512 | 0.012 | 24 | - | 41410546.7 benchmark_oneAxisRotation | 512 | 0.033 | 63 | 2.638 | 15694929.8 benchmark_SimTK_oneAxisRotation * | 4096 | 0.098 | 24 | - | 41644214.4 benchmark_oneAxisRotation | 4096 | 0.262 | 64 | 2.668 | 15611005.5 benchmark_SimTK_oneAxisRotation * | 8192 | 0.197 | 24 | - | 41656920.3 benchmark_oneAxisRotation | 8192 | 0.524 | 64 | 2.666 | 15623808.0

#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