SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST_F() [25/72]

SpicesTest::TEST_F ( MemoryPool_test ,
Performance_RandomSize_OneThread  )

Testing Spices::MemoryPool Performance.

Definition at line 411 of file MemoryPool_test.h.

411 {
412
414
415 static constexpr int nThread = 1;
416 static constexpr int nCount = 500000;
417 static constexpr int maxBytes = 1024;
418
419 {
420 SPICESTEST_PROFILE_SCOPE("malloc / free");
421
422 std::vector<std::thread> threads;
423 for (int i = 0; i < nThread; i++)
424 {
425 std::thread t1([&]() {
426 std::vector<void*> objects;
427 objects.resize(nCount);
428
429 for (int j = 0; j < nCount; j++)
430 {
431 const size_t bytes = maxBytes * std::rand() / float(RAND_MAX);
432 void* p = malloc(bytes);
433
434 objects[j] = std::move(p);
435 }
436
437 for (int j = 0; j < nCount; j++)
438 {
439 void* p = objects[j];
440
441 free(p);
442 }
443 });
444
445 threads.push_back(std::move(t1));
446 }
447
448 for (int i = 0; i < nThread; i++)
449 {
450 threads[i].join();
451 }
452 }
453
454 {
455 SPICESTEST_PROFILE_SCOPE("MemoryPool::Alloc / MemoryPool::Free");
456
457 std::vector<std::thread> threads;
458 for (int i = 0; i < nThread; i++)
459 {
460 std::thread t1([&]() {
461 std::vector<void*> objects;
462 objects.resize(nCount);
463
464 for (int j = 0; j < nCount; j++)
465 {
466 size_t bytes = maxBytes * std::rand() / float(RAND_MAX);
467 bytes = std::max((size_t)8, bytes);
468 void* p = Spices::MemoryPool::Alloc(bytes);
469
470 objects[j] = std::move(p);
471 }
472
473 for (int j = 0; j < nCount; j++)
474 {
475 void* p = objects[j];
476
478 }
479 });
480
481 threads.push_back(std::move(t1));
482 }
483
484 for (int i = 0; i < nThread; i++)
485 {
486 threads[i].join();
487 }
488 }
489 }
#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().