32 #include <gtest/gtest.h> 36 TEST(BlockmemGridmap, SpacialAccessPerformance)
38 constexpr
int size[3] =
42 constexpr
int pad[3] =
46 constexpr
int range = 0x10;
52 using ThreeDimArrayFloat = std::array<std::array<std::array<float, size[0]>, size[1]>, size[2]>;
54 std::shared_ptr<ThreeDimArrayFloat> array(
new ThreeDimArrayFloat);
55 std::shared_ptr<ThreeDimArrayFloat> array_ret(
new ThreeDimArrayFloat);
58 gm_ret.
reset(Vec(size));
62 for (i[0] = 0; i[0] < size[0]; ++i[0])
64 for (i[1] = 0; i[1] < size[1]; ++i[1])
66 for (i[2] = 0; i[2] < size[2]; ++i[2])
68 gm[i] = i[2] * 0x100 + i[1] * 0x10 + i[0];
69 (*array)[i[2]][i[1]][i[0]] = gm[i];
74 for (i[0] = pad[0]; i[0] < size[0] - pad[0]; ++i[0])
76 for (i[1] = pad[1]; i[1] < size[1] - pad[1]; ++i[1])
78 for (i[2] = pad[2]; i[2] < size[2] - pad[2]; ++i[2])
80 ASSERT_EQ(gm[i], (*array)[i[2]][i[1]][i[0]]);
86 const auto ts0 = boost::chrono::high_resolution_clock::now();
87 for (i[0] = pad[0]; i[0] < size[0] - pad[0]; ++i[0])
89 for (i[1] = pad[1]; i[1] < size[1] - pad[1]; ++i[1])
91 for (i[2] = pad[2]; i[2] < size[2] - pad[2]; ++i[2])
96 for (j[0] = -range; j[0] <= range; ++j[0])
98 for (j[1] = -range; j[1] <= range; ++j[1])
100 for (j[2] = -range; j[2] <= range; ++j[2])
102 const Vec ij = i + j;
111 std::cerr << std::endl;
112 const auto te0 = boost::chrono::high_resolution_clock::now();
113 std::cout <<
"BlockMemGridmap<3, 2>: " << boost::chrono::duration<float>(te0 - ts0).count() << std::endl;
116 const auto ts1 = boost::chrono::high_resolution_clock::now();
117 for (i[0] = pad[0]; i[0] < size[0] - pad[0]; ++i[0])
119 for (i[1] = pad[1]; i[1] < size[1] - pad[1]; ++i[1])
121 for (i[2] = pad[2]; i[2] < size[2] - pad[2]; ++i[2])
124 (*array_ret)[i[2]][i[1]][i[0]] = 0;
126 for (j[0] = -range; j[0] <= range; ++j[0])
128 for (j[1] = -range; j[1] <= range; ++j[1])
130 for (j[2] = -range; j[2] <= range; ++j[2])
132 const Vec ij = i + j;
133 (*array_ret)[i[2]][i[1]][i[0]] += (*array)[ij[2]][ij[1]][ij[0]];
141 std::cerr << std::endl;
142 const auto te1 = boost::chrono::high_resolution_clock::now();
143 std::cout <<
"Array[][][]: " << boost::chrono::duration<float>(te1 - ts1).count() << std::endl;
146 for (i[0] = 0x200; i[0] < size[0] - 0x200; ++i[0])
148 for (i[1] = 0x200; i[1] < size[1] - 0x200; ++i[1])
150 for (i[2] = 0x10; i[2] < size[2] - 0x10; ++i[2])
152 ASSERT_EQ(gm_ret[i], (*array_ret)[i[2]][i[1]][i[0]]);
158 ASSERT_LT(te0 - ts0, te1 - ts1);
161 int main(
int argc,
char** argv)
163 testing::InitGoogleTest(&argc, argv);
165 return RUN_ALL_TESTS();
void reset(const CyclicVecInt< DIM, NONCYCLIC > &size)