From 26c14c500e10189a9f40ff3d74d4901a0c62e27d Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Mon, 7 Apr 2025 03:00:34 -0700 Subject: [PATCH] Fix bug in testspeed.cc for models that do not invoke the constraint solver. PiperOrigin-RevId: 744650422 Change-Id: I0d49b7a3f3069f0c066e8758627e95f973b3a728 --- sample/compile.cc | 16 +++++++--------- sample/testspeed.cc | 13 ++++++------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/sample/compile.cc b/sample/compile.cc index a5a572d8..14382393 100644 --- a/sample/compile.cc +++ b/sample/compile.cc @@ -18,7 +18,6 @@ #include #include #include -#include #include @@ -30,13 +29,12 @@ static constexpr char helpstring[] = " if infile is mjcf, compilation will be timed twice to measure the impact of caching\n\n" " Example: compile model.xml [model.mjb]\n"; -// timer +// timer (seconds) mjtNum gettm(void) { - using std::chrono::steady_clock; - using Microseconds = std::chrono::duration; - static steady_clock::time_point tm_start = steady_clock::now(); - auto elapsed = Microseconds(steady_clock::now() - tm_start); - return elapsed.count(); + using Clock = std::chrono::steady_clock; + using Seconds = std::chrono::duration; + static const Clock::time_point tm_start = Clock::now(); + return Seconds(Clock::now() - tm_start).count(); } // deallocate and print message @@ -140,12 +138,12 @@ int main(int argc, char** argv) { if (type1==typeXML) { double starttime = gettm(); m = mj_loadXML(argv[1], 0, error, 1000); - first = 1e-6 * (gettm() - starttime); + first = gettm() - starttime; if (m) { mj_deleteModel(m); starttime = gettm(); m = mj_loadXML(argv[1], 0, error, 1000); - second = 1e-6 * (gettm() - starttime); + second = gettm() - starttime; } } else { m = mj_loadModel(argv[1], 0); diff --git a/sample/testspeed.cc b/sample/testspeed.cc index 3791bf5b..84eb78bd 100644 --- a/sample/testspeed.cc +++ b/sample/testspeed.cc @@ -36,13 +36,12 @@ int constraints[maxthread]; mjtNum iterations[maxthread]; mjtNum simtime[maxthread]; -// timer +// timer (microseconds) mjtNum gettm(void) { - using std::chrono::steady_clock; - using Microseconds = std::chrono::duration; - static steady_clock::time_point tm_start = steady_clock::now(); - auto elapsed = Microseconds(steady_clock::now() - tm_start); - return elapsed.count(); + using Clock = std::chrono::steady_clock; + using Microseconds = std::chrono::duration; + static const Clock::time_point tm_start = Clock::now(); + return Microseconds(Clock::now() - tm_start).count(); } // deallocate and print message @@ -99,7 +98,7 @@ void simulate(int id, int nstep, mjtNum* ctrl) { contacts[id] += d[id]->ncon; constraints[id] += d[id]->nefc; int nisland = d[id]->solver_nisland; - if (nisland == 1) { + if (nisland == 1 || nisland == 0) { iterations[id] += d[id]->solver_niter[0]; } else { mjtNum niter = 0;