Fix bug in testspeed.cc for models that do not invoke the constraint solver.

PiperOrigin-RevId: 744650422
Change-Id: I0d49b7a3f3069f0c066e8758627e95f973b3a728
This commit is contained in:
Yuval Tassa
2025-04-07 03:00:34 -07:00
committed by Copybara-Service
parent d05251af2a
commit 26c14c500e
2 changed files with 13 additions and 16 deletions
+7 -9
View File
@@ -18,7 +18,6 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <ratio>
#include <mujoco/mujoco.h> #include <mujoco/mujoco.h>
@@ -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" " if infile is mjcf, compilation will be timed twice to measure the impact of caching\n\n"
" Example: compile model.xml [model.mjb]\n"; " Example: compile model.xml [model.mjb]\n";
// timer // timer (seconds)
mjtNum gettm(void) { mjtNum gettm(void) {
using std::chrono::steady_clock; using Clock = std::chrono::steady_clock;
using Microseconds = std::chrono::duration<double, std::micro>; using Seconds = std::chrono::duration<mjtNum>;
static steady_clock::time_point tm_start = steady_clock::now(); static const Clock::time_point tm_start = Clock::now();
auto elapsed = Microseconds(steady_clock::now() - tm_start); return Seconds(Clock::now() - tm_start).count();
return elapsed.count();
} }
// deallocate and print message // deallocate and print message
@@ -140,12 +138,12 @@ int main(int argc, char** argv) {
if (type1==typeXML) { if (type1==typeXML) {
double starttime = gettm(); double starttime = gettm();
m = mj_loadXML(argv[1], 0, error, 1000); m = mj_loadXML(argv[1], 0, error, 1000);
first = 1e-6 * (gettm() - starttime); first = gettm() - starttime;
if (m) { if (m) {
mj_deleteModel(m); mj_deleteModel(m);
starttime = gettm(); starttime = gettm();
m = mj_loadXML(argv[1], 0, error, 1000); m = mj_loadXML(argv[1], 0, error, 1000);
second = 1e-6 * (gettm() - starttime); second = gettm() - starttime;
} }
} else { } else {
m = mj_loadModel(argv[1], 0); m = mj_loadModel(argv[1], 0);
+6 -7
View File
@@ -36,13 +36,12 @@ int constraints[maxthread];
mjtNum iterations[maxthread]; mjtNum iterations[maxthread];
mjtNum simtime[maxthread]; mjtNum simtime[maxthread];
// timer // timer (microseconds)
mjtNum gettm(void) { mjtNum gettm(void) {
using std::chrono::steady_clock; using Clock = std::chrono::steady_clock;
using Microseconds = std::chrono::duration<double, std::micro>; using Microseconds = std::chrono::duration<mjtNum, std::micro>;
static steady_clock::time_point tm_start = steady_clock::now(); static const Clock::time_point tm_start = Clock::now();
auto elapsed = Microseconds(steady_clock::now() - tm_start); return Microseconds(Clock::now() - tm_start).count();
return elapsed.count();
} }
// deallocate and print message // deallocate and print message
@@ -99,7 +98,7 @@ void simulate(int id, int nstep, mjtNum* ctrl) {
contacts[id] += d[id]->ncon; contacts[id] += d[id]->ncon;
constraints[id] += d[id]->nefc; constraints[id] += d[id]->nefc;
int nisland = d[id]->solver_nisland; int nisland = d[id]->solver_nisland;
if (nisland == 1) { if (nisland == 1 || nisland == 0) {
iterations[id] += d[id]->solver_niter[0]; iterations[id] += d[id]->solver_niter[0];
} else { } else {
mjtNum niter = 0; mjtNum niter = 0;