diff --git a/test/benchmark/parse_benchmark_test.cc b/test/benchmark/parse_benchmark_test.cc index ba34cfc7..cd8957c8 100644 --- a/test/benchmark/parse_benchmark_test.cc +++ b/test/benchmark/parse_benchmark_test.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include "test/fixture.h" @@ -93,6 +94,37 @@ void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseHumanoid100(benchmark::State& state) { } BENCHMARK(BM_ParseHumanoid100); +void BM_CompileManyTextures(benchmark::State& state) { + MujocoErrorTestGuard guard; // Fail test if there are any mujoco errors + std::string texture_path = + GetTestDataFilePath("benchmark/testdata/noise.png"); + + // Create a model with many textures + std::string xml = "\n"; + xml += " \n"; + for (int i = 0; i < state.range(0); ++i) { + xml += absl::StrFormat(" \n", + i, texture_path); + } + xml += " \n"; + xml += " \n"; + xml += " \n"; + xml += " \n"; + xml += "\n"; + + // Disable cache to simulate many textures without needing separate + // testdata files. + mj_setCacheCapacity(mj_getCache(), 0); + + for (auto s : state) { + char error[1024]; + mjModel* model = LoadModelFromString(xml, error, sizeof(error)); + mj_deleteModel(model); + } +} + +BENCHMARK(BM_CompileManyTextures)->Range(10, 100); + } // namespace void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseCacheHits(benchmark::State& state) {