| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| |
|
| | #include <array> |
| | #include <memory> |
| | #include <string> |
| |
|
| | #include <benchmark/benchmark.h> |
| | #include <gmock/gmock.h> |
| | #include <gtest/gtest.h> |
| | #include <absl/base/attributes.h> |
| | #include <mujoco/mjmodel.h> |
| | #include <mujoco/mujoco.h> |
| | #include "test/fixture.h" |
| |
|
| | namespace mujoco { |
| | namespace { |
| |
|
| | using ::testing::Eq; |
| | using ::testing::NotNull; |
| |
|
| |
|
| | static void run_parse_benchmark(const std::string xml_path, |
| | benchmark::State& state) { |
| | MujocoErrorTestGuard guard; |
| |
|
| | int vfs_errno = 0; |
| | std::string vfs_errmsg = ""; |
| | auto vfs = std::make_unique<mjVFS>(); |
| | mj_defaultVFS(vfs.get()); |
| |
|
| | if ((vfs_errno = mj_addFileVFS(vfs.get(), "", xml_path.data()))) { |
| | if (vfs_errno == 1) { |
| | vfs_errmsg = "VFS is full"; |
| | } else if (vfs_errno == 2) { |
| | vfs_errmsg = "Repeated name in VFS"; |
| | } else { |
| | vfs_errmsg = "File not found"; |
| | } |
| | } |
| |
|
| | ASSERT_THAT(vfs_errno, Eq(0)) << "Failed to add file to VFS: " << vfs_errmsg; |
| |
|
| | |
| | std::array<char, 1024> error; |
| | mjModel* model = |
| | mj_loadXML(xml_path.data(), vfs.get(), error.data(), error.size()); |
| | 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); |
| | mj_deleteVFS(vfs.get()); |
| | } |
| |
|
| | |
| | |
| | |
| |
|
| | void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseFlagPlugin(benchmark::State& state) { |
| | run_parse_benchmark(GetModelPath("flex/flag.xml"), state); |
| | } |
| | BENCHMARK(BM_ParseFlagPlugin); |
| |
|
| | void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseFlag(benchmark::State& state) { |
| | run_parse_benchmark(GetModelPath("../test/benchmark/testdata/flag.xml"), |
| | state); |
| | } |
| | BENCHMARK(BM_ParseFlag); |
| |
|
| | void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseHumanoid(benchmark::State& state) { |
| | run_parse_benchmark(GetModelPath("humanoid/humanoid.xml"), state); |
| | } |
| | BENCHMARK(BM_ParseHumanoid); |
| |
|
| | void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseHumanoid100(benchmark::State& state) { |
| | run_parse_benchmark(GetModelPath("humanoid/humanoid100.xml"), state); |
| | } |
| | BENCHMARK(BM_ParseHumanoid100); |
| |
|
| | } |
| | } |
| |
|