-2
unsigned int lookup_bloom(unsigned char (*id)[HEXXID], unsigned int len,
void *bf)
{
int i;
struct bloom_structure *filter = (struct bloom_structure *) bf;
unsigned int *nexthop = NULL;
// The returned values of counting_bloom_check() are 0 if found else 1
unsigned char matchvec[WDIST] = {1};
unsigned char tmp1[HEXXID + 1] = {0};
unsigned char tmp2[HEXXID] = {0};
memcpy(tmp1, id, HEXXID);
memcpy(tmp2, tmp2, HEXXID);
// Although the paper suggests to perform parallel membership queries
for (i = len; i >= MINLENGTH; i--) {
tmp1[i/BYTE] = tmp1[i/BYTE] >> (BYTE - i % BYTE) <<
(BYTE - i % BYTE);
if (!filter->flag[i - MINLENGTH])
continue;
matchvec[i - MINLENGTH] =
counting_bloom_check(filter->bloom[i - MINLENGTH], tmp1,
HEXXID);
}
// Parse the matchvec from longest to shortest to perform table search
for (i = len; i >= MINLENGTH; i--) {
tmp2[i/BYTE] = tmp2[i/BYTE] >> (BYTE - i % BYTE) <<
(BYTE - i % BYTE);
if (matchvec[i - MINLENGTH] || !filter->flag[i - MINLENGTH])
continue;
nexthop = hashit_lookup(filter->hashtable[i - MINLENGTH],
tmp2);
if (nexthop)
return *nexthop;
}
return 0;
}
下面是在代碼中使用的一些定義:我對這個函數做了哪些改變來優化執行時間?
#define WDIST 140
#define MINLENGTH 20
struct bloom_structure {
bool flag[WDIST];
unsigned int length[WDIST];
int low[WDIST];
int high[WDIST];
counting_bloom_t *bloom[WDIST];
hash_t hashtable[WDIST];
};
我測量這個函數的執行時間。 有人能幫我優化這個例程嗎?
如果有人可以建議任何更改以編寫循環以減少執行時間,那將會很棒。
謝謝您提前!
分析。並測量每一段代碼,看看瓶頸在哪裏(這基本上是分析)。 –