Tweaks to benchmarks.

- Modify parse_benchmark_test to not time the first instance of file loading.
- Improve readability of step_benchmark_test.

PiperOrigin-RevId: 680953562
Change-Id: I4569d1b946ecb49b6590ea313f0b598ffc897888
This commit is contained in:
Yuval Tassa
2024-10-01 04:07:33 -07:00
committed by Copybara-Service
parent cb745db412
commit 62ec802ec1
2 changed files with 9 additions and 7 deletions
+6 -3
View File
@@ -54,11 +54,14 @@ static void run_parse_benchmark(const std::string xml_path,
ASSERT_THAT(vfs_errno, Eq(0)) << "Failed to add file to VFS: " << vfs_errmsg;
// load once to warm up filesystem and compiler cache
std::array<char, 1024> error;
for (auto s : state) {
mjModel* model =
mjModel* model =
mj_loadXML(xml_path.data(), vfs.get(), error.data(), error.size());
ASSERT_THAT(model, NotNull()) << "Failed to load model: " << error.data();
ASSERT_THAT(model, NotNull()) << "Failed to load model: " << error.data();
for (auto s : state) {
mjModel* model = mj_loadXML(xml_path.data(), vfs.get(), 0, 0);
mj_deleteModel(model);
}
state.SetLabel(xml_path);
+3 -4
View File
@@ -17,8 +17,6 @@
#include <vector>
#include <benchmark/benchmark.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <absl/base/attributes.h>
#include <mujoco/mjdata.h>
#include <mujoco/mjmodel.h>
@@ -57,8 +55,9 @@ static void run_step_benchmark(const mjModel* model, benchmark::State& state) {
while (state.KeepRunningBatch(kNumBenchmarkSteps)) {
mj_setState(model, data, initial_state.data(), spec);
for (int i=kNumWarmupSteps; i < nsteps; i++) {
mju_copy(data->ctrl, ctrl.data()+model->nu*i, model->nu);
for (int i=0; i < kNumBenchmarkSteps; i++) {
mjtNum* ctrl_data = ctrl.data()+model->nu*(i+kNumWarmupSteps);
mju_copy(data->ctrl, ctrl_data, model->nu);
mj_step(model, data);
}
}