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 <cstring>
#include <iostream>
#include <ratio>
#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"
" Example: compile model.xml [model.mjb]\n";
// timer
// timer (seconds)
mjtNum gettm(void) {
using std::chrono::steady_clock;
using Microseconds = std::chrono::duration<double, std::micro>;
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<mjtNum>;
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);
+6 -7
View File
@@ -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<double, std::micro>;
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<mjtNum, std::micro>;
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;