SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST_F() [23/72]

SpicesTest::TEST_F ( MemoryPool_test ,
Performance_FixedSize_OneThread  )

Testing Spices::MemoryPool Performance.

Definition at line 179 of file MemoryPool_test.h.

179 {
180
182
183 static constexpr int nThread = 1;
184 static constexpr int nCount = 500000;
185
186 {
187 SPICESTEST_PROFILE_SCOPE("new / delete");
188
189 std::vector<std::thread> threads;
190 for (int i = 0; i < nThread; i++)
191 {
192 std::thread t1([&]() {
193 std::vector<MemoryPoolTest*> objects;
194 objects.resize(nCount);
195
196 for (int j = 0; j < nCount; j++)
197 {
199
200 objects[j] = std::move(p);
201 }
202
203 for (int j = 0; j < nCount; j++)
204 {
205 MemoryPoolTest* p = objects[j];
206 delete p;
207 }
208 });
209
210 threads.push_back(std::move(t1));
211 }
212
213 for (int i = 0; i < nThread; i++)
214 {
215 threads[i].join();
216 }
217 }
218
219 {
220 SPICESTEST_PROFILE_SCOPE("malloc / free");
221
222 std::vector<std::thread> threads;
223 for (int i = 0; i < nThread; i++)
224 {
225 std::thread t1([&]() {
226 std::vector<MemoryPoolTest*> objects;
227 objects.resize(nCount);
228
229 for (int j = 0; j < nCount; j++)
230 {
231 MemoryPoolTest* p = static_cast<MemoryPoolTest*>(malloc(4 * sizeof(MemoryPoolTest)));
232 new(p)MemoryPoolTest;
233
234 objects[j] = std::move(p);
235 }
236
237 for (int j = 0; j < nCount; j++)
238 {
239 MemoryPoolTest* p = objects[j];
240
241 p->~MemoryPoolTest();
242 free(p);
243 }
244 });
245
246 threads.push_back(std::move(t1));
247 }
248
249 for (int i = 0; i < nThread; i++)
250 {
251 threads[i].join();
252 }
253 }
254
255 {
256 SPICESTEST_PROFILE_SCOPE("MemoryPool::Alloc / MemoryPool::Free");
257
258 std::vector<std::thread> threads;
259 for (int i = 0; i < nThread; i++)
260 {
261 std::thread t1([&]() {
262 std::vector<MemoryPoolTest*> objects;
263 objects.resize(nCount);
264
265 for (int j = 0; j < nCount; j++)
266 {
267 MemoryPoolTest* p = static_cast<MemoryPoolTest*>(Spices::MemoryPool::Alloc(4 * sizeof(MemoryPoolTest)));
268 new(p)MemoryPoolTest;
269
270 objects[j] = std::move(p);
271 }
272
273 for (int j = 0; j < nCount; j++)
274 {
275 MemoryPoolTest* p = objects[j];
276
277 p->~MemoryPoolTest();
279 }
280 });
281
282 threads.push_back(std::move(t1));
283 }
284
285 for (int i = 0; i < nThread; i++)
286 {
287 threads[i].join();
288 }
289 }
290 }
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICESTEST_PROFILE_FUNCTION()
static void * Alloc(size_t size)
Alloc memory entry point.
static void Free(void *ptr)
Free memory entry point.

References Spices::MemoryPool::Free().