diff --git a/test/benchmark/parse_benchmark_test.cc b/test/benchmark/parse_benchmark_test.cc index e528322b..be01e33f 100644 --- a/test/benchmark/parse_benchmark_test.cc +++ b/test/benchmark/parse_benchmark_test.cc @@ -15,6 +15,8 @@ // A benchmark for parsing and compiling models from XML. #include +#include +#include #include #include @@ -27,21 +29,40 @@ namespace mujoco { namespace { +using ::testing::Eq; using ::testing::NotNull; -static void run_parse_benchmark(const std::string xml_path, benchmark::State& state) { + +static void run_parse_benchmark(const std::string xml_path, + benchmark::State& state) { MujocoErrorTestGuard guard; // Fail test if there are any mujoco errors + int vfs_errno = 0; + std::string vfs_errmsg = ""; + auto vfs = std::make_unique(); + mj_defaultVFS(vfs.get()); + + if ((vfs_errno = mj_addFileVFS(vfs.get(), "", xml_path.data()))) { + if (vfs_errno == 1) { + vfs_errmsg = "VFS is full"; // should not occur + } else if (vfs_errno == 2) { + vfs_errmsg = "Repeated name in VFS"; // should not occur + } else { + vfs_errmsg = "File not found"; + } + } + + ASSERT_THAT(vfs_errno, Eq(0)) << "Failed to add file to VFS: " << vfs_errmsg; + std::array error; for (auto s : state) { - // TODO(nimrod): Load the models from VFS rather than from disk, to - // limit the benchmark to the parsing and model compilation speed. mjModel* model = - mj_loadXML(xml_path.data(), nullptr, error.data(), error.size()); + mj_loadXML(xml_path.data(), vfs.get(), error.data(), error.size()); ASSERT_THAT(model, NotNull()) << "Failed to load model: " << error.data(); mj_deleteModel(model); } state.SetLabel(xml_path); + mj_deleteVFS(vfs.get()); } // Use ABSL_ATTRIBUTE_NO_TAIL_CALL to make sure the benchmark functions appear diff --git a/test/benchmark/step_benchmark_test.cc b/test/benchmark/step_benchmark_test.cc index 1c369e84..d2b6963d 100644 --- a/test/benchmark/step_benchmark_test.cc +++ b/test/benchmark/step_benchmark_test.cc @@ -14,7 +14,7 @@ // A benchmark which steps various models without rendering, and measures speed. -#include +#include #include #include @@ -28,17 +28,12 @@ namespace mujoco { namespace { -// number of steps to roll out before benhmarking +// number of steps to roll out before benchmarking static const int kNumWarmupSteps = 500; // number of steps to benchmark static const int kNumBenchmarkSteps = 50; -// copy array into vector -std::vector AsVector(const mjtNum* array, int n) { - return std::vector(array, array + n); -} - static void run_step_benchmark(const mjModel* model, benchmark::State& state) { mjData* data = mj_makeData(model);