This repository was archived by the owner on Feb 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathintrospectionmanager_stress.cc
97 lines (82 loc) · 2.8 KB
/
introspectionmanager_stress.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* Copyright (C) 2018 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <gtest/gtest.h>
#include <numeric>
#include "gazebo/util/IntrospectionManager.hh"
#include "gazebo/test/ServerFixture.hh"
#include "ignition/math/Pose3.hh"
using namespace gazebo;
/// \brief A test fixture class.
class IntrospectionManagerTest : public ::testing::Test
{
/// \brief Constructor
public: IntrospectionManagerTest()
{
this->manager = util::IntrospectionManager::Instance();
}
/// \brief Initialize the test
public: void SetUp()
{
}
public: void TearDown()
{
// Unregister multiple items.
this->manager->Clear();
EXPECT_TRUE(this->manager->Items().empty());
}
/// \brief Pointer to the introspection manager.
protected: util::IntrospectionManager *manager;
};
TEST_F(IntrospectionManagerTest, IntrospectionManagerStressTest)
{
// Each model registers 5 items (pos, linvel, angvel, linaccel, angaccel)
// This would be the equivalent of adding 2000 models.
for (size_t ii = 0; ii < 10000; ii++)
{
// A callback for updating items.
// This arbitrarily captures something large enough to not
// use SBO for std::function.
auto func = [this,
a = std::string("asdfasdfasdfasdf"),
b = std::string("asdfasdfasdfasdf"),
c = std::string("asdfasdfasdfasdf"),
d = std::string("asdfasdfasdfasdf")]()
{
return a + b + c + d;
};
std::stringstream ss;
ss << "item" << ii;
EXPECT_TRUE(this->manager->Register<std::string>(ss.str(), func));
}
std::vector<double> times;
for (size_t ii = 0; ii < 1000; ++ii)
{
common::Time startTime = common::Time::GetWallTime();
this->manager->Update();
common::Time endTime = common::Time::GetWallTime();
times.push_back((endTime - startTime).Double());
}
auto n = times.size();
std::sort(times.begin(), times.end());
auto sum = std::accumulate(times.begin(), times.end(), 0.0);
std::cerr << "Samples: " << n << std::endl;
std::cerr << "Max: " << times.back() << std::endl;
std::cerr << "Min: " << times.front() << std::endl;
// Not exactly median, but really close.
std::cerr << "Median: " << times[n/2] << std::endl;
std::cerr << "Mean: " << sum / static_cast<double>(n) << std::endl;
}