コード例 #1
0
void demo(uint32_t N) {
  printf("N = %d\n", N);
  uint32_t * z = malloc(N * sizeof(uint32_t));
  for(uint32_t i = 0 ; i < N; ++i) z[i] = rand(); // some rand. number
  uint32_t nmbr = 500;
  uint32_t * accesses = malloc(nmbr * sizeof(uint32_t));
  for(uint32_t i = 0 ; i < nmbr; ++i) accesses[i] = rand(); // some rand. number
  uint32_t expected1 = modsum(z,N,accesses,nmbr);
  uint32_t expected2 = fastsum(z,N,accesses,nmbr);
  BEST_TIME(modsum(z,N,accesses,nmbr), expected1, 1000, nmbr);
  BEST_TIME(fastsum(z,N,accesses,nmbr), expected2, 1000, nmbr);
#ifdef __AVX2__
  uint32_t expected3 = vectorsum(z,N,accesses,nmbr);
  if(N % 4 == 0) BEST_TIME(vectorsum(z,N,accesses,nmbr), expected3, 1000, nmbr);
  uint32_t expected4 = maskedvectorsum(z,N,accesses,nmbr);
  if(N % 8 == 0) BEST_TIME(maskedvectorsum(z,N,accesses,nmbr), expected4, 1000, nmbr);
#endif
  free(z);
  free(accesses);
}
コード例 #2
0
ファイル: shopping_offers.cpp プロジェクト: YhgzXxfz/leetcode
 void addTo(vector<int>& cart, vector<int>& offer, int& cost, vector<int>& price, int& min_cost, vector<int>& needs, int i) {
     vectorsum(cart, offer);
     cost += (offer[offer.size()-1]-sums[i]);
     if (underfit(cart, needs)) min_cost = min(min_cost, cost);
 }