Skip to content

Commit

Permalink
Tweaks to benchmarks.
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
yuvaltassa authored and copybara-github committed Oct 1, 2024
1 parent cb745db commit 62ec802
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 6 additions & 3 deletions test/benchmark/parse_benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions test/benchmark/step_benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 62ec802

Please sign in to comment.