-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];
};
我测量这个函数的执行时间。 有人能帮我优化这个例程吗?
如果有人可以建议任何更改以编写循环以减少执行时间,那将会很棒。
谢谢您提前!
分析。并测量每一段代码,看看瓶颈在哪里(这基本上是分析)。 –