【发布时间】:2015-08-30 14:49:00
【问题描述】:
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];
};
我正在测量这个函数的执行时间。 有人可以帮我优化这个程序吗?
如果有人可以建议对编写循环进行任何更改以减少执行时间,那就太好了。
提前谢谢你!
【问题讨论】:
-
分析。并测量每一段代码,看看瓶颈在哪里(这基本上就是分析所做的)。
标签: c performance optimization