Add parsing benchmark simulating many textures.
PiperOrigin-RevId: 857883857 Change-Id: Ia428ff8aeba4fbaae67a6337d0856cd2b19af2e6
This commit is contained in:
committed by
Copybara-Service
parent
bb4df33adf
commit
799f8a300e
@@ -22,6 +22,7 @@
|
|||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <absl/base/attributes.h>
|
#include <absl/base/attributes.h>
|
||||||
|
#include <absl/strings/str_format.h>
|
||||||
#include <mujoco/mjmodel.h>
|
#include <mujoco/mjmodel.h>
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "test/fixture.h"
|
#include "test/fixture.h"
|
||||||
@@ -93,6 +94,37 @@ void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseHumanoid100(benchmark::State& state) {
|
|||||||
}
|
}
|
||||||
BENCHMARK(BM_ParseHumanoid100);
|
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 = "<mujoco>\n";
|
||||||
|
xml += " <asset>\n";
|
||||||
|
for (int i = 0; i < state.range(0); ++i) {
|
||||||
|
xml += absl::StrFormat(" <texture name='tex%d' type='2d' file='%s'/>\n",
|
||||||
|
i, texture_path);
|
||||||
|
}
|
||||||
|
xml += " </asset>\n";
|
||||||
|
xml += " <worldbody>\n";
|
||||||
|
xml += " <geom size='1'/>\n";
|
||||||
|
xml += " </worldbody>\n";
|
||||||
|
xml += "</mujoco>\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
|
} // namespace
|
||||||
|
|
||||||
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseCacheHits(benchmark::State& state) {
|
void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseCacheHits(benchmark::State& state) {
|
||||||
|
|||||||
Reference in New Issue
Block a user