Advertisement
Guest User

UE4 Lib Benchmark

a guest
May 13th, 2017
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. int UCppFunctionLibrary::CalculateSomethingCpp(int InNumTimes)
  2. {
  3.     TArray<int> TestArray;
  4.  
  5.     const int ELEMENTS_NUM = 100;
  6.     const int MAX_RAND = 10000;
  7.     const int NUM_TIMES = InNumTimes;
  8.     int MinSum = 0; // to prevent redundant optimizations
  9.     int Min = 0; // here because BPs have no inner visibility scopes
  10.  
  11.     // same as BP (this way choosen because BPs have no Reserve() function)
  12.     for (int i = 0; i < ELEMENTS_NUM; ++i)
  13.     {
  14.         TestArray.Push(i);
  15.     }
  16.  
  17.     for (int i = 0; i < NUM_TIMES; ++i)
  18.     {
  19.         for (int j = 0; j < ELEMENTS_NUM; ++j)
  20.         {
  21.             TestArray[j] = FMath::RandHelper(MAX_RAND); // same as BP
  22.         }
  23.  
  24.         Min = MAX_RAND;
  25.         for (auto& Number : TestArray)
  26.         {
  27.             if (Number < Min)
  28.             {
  29.                 Min = Number;
  30.             }
  31.         }
  32.         MinSum += Min;
  33.     }
  34.  
  35.     return MinSum;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement