SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST_F() [24/72]

SpicesTest::TEST_F ( MemoryPool_test ,
Performance_RandomSize_MultiThread  )

Testing Spices::MemoryPool Performance.

Definition at line 494 of file MemoryPool_test.h.

494 {
495
497
498 static constexpr int nThread = 10;
499 static constexpr int nCount = 50000;
500 static constexpr int maxBytes = 1024;
501
502 {
503 SPICESTEST_PROFILE_SCOPE("malloc / free");
504
505 std::vector<std::thread> threads;
506 for (int i = 0; i < nThread; i++)
507 {
508 std::thread t1([&]() {
509 std::vector<void*> objects;
510 objects.resize(nCount);
511
512 for (int j = 0; j < nCount; j++)
513 {
514 const size_t bytes = maxBytes * std::rand() / float(RAND_MAX);
515 void* p = malloc(bytes);
516
517 objects[j] = std::move(p);
518 }
519
520 for (int j = 0; j < nCount; j++)
521 {
522 void* p = objects[j];
523
524 free(p);
525 }
526 });
527
528 threads.push_back(std::move(t1));
529 }
530
531 for (int i = 0; i < nThread; i++)
532 {
533 threads[i].join();
534 }
535 }
536
537 {
538 SPICESTEST_PROFILE_SCOPE("MemoryPool::Alloc / MemoryPool::Free");
539
540 std::vector<std::thread> threads;
541 for (int i = 0; i < nThread; i++)
542 {
543 std::thread t1([&]() {
544 std::vector<void*> objects;
545 objects.resize(nCount);
546
547 for (int j = 0; j < nCount; j++)
548 {
549 size_t bytes = maxBytes * std::rand() / float(RAND_MAX);
550 bytes = std::max((size_t)8, bytes);
551 void* p = Spices::MemoryPool::Alloc(bytes);
552
553 objects[j] = std::move(p);
554 }
555
556 for (int j = 0; j < nCount; j++)
557 {
558 void* p = objects[j];
559
561 }
562 });
563
564 threads.push_back(std::move(t1));
565 }
566
567 for (int i = 0; i < nThread; i++)
568 {
569 threads[i].join();
570 }
571 }
572 }
#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().