mirror of
git://git.code.sf.net/p/dhcpd-pools/code
synced 2025-12-16 15:57:00 +00:00
analyze: sort ranges before analysis
At the other day I where wondering why so much time was spent on analysis function, when I realized regression. At the time uthash was introduced to the project range sorting got to be dropped, which caused same leases to be walked in analysis time after time. Now when the regression is removed, and the test cases run about 28% over all quicker. The rule of thumb is that the greater the data set the bigger is the benefit having this fix. My largest test data is now roughly 35% faster. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
7a86746710
commit
18f2835fd5
1 changed files with 9 additions and 4 deletions
|
|
@ -55,6 +55,8 @@ int prepare_data(void)
|
||||||
{
|
{
|
||||||
/* Sort leases */
|
/* Sort leases */
|
||||||
HASH_SORT(leases, ip_sort);
|
HASH_SORT(leases, ip_sort);
|
||||||
|
/* Sort ranges */
|
||||||
|
qsort(ranges, (size_t) num_ranges, sizeof(struct range_t), &rangecomp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,17 +64,20 @@ int prepare_data(void)
|
||||||
int do_counting(void)
|
int do_counting(void)
|
||||||
{
|
{
|
||||||
struct range_t *restrict range_p;
|
struct range_t *restrict range_p;
|
||||||
const struct leases_t *restrict l;
|
const struct leases_t *restrict l = leases;
|
||||||
unsigned long i, k, block_size;
|
unsigned long i, k, block_size;
|
||||||
|
|
||||||
range_p = ranges;
|
|
||||||
unsigned long r_end;
|
unsigned long r_end;
|
||||||
|
range_p = ranges;
|
||||||
|
|
||||||
/* Walk through ranges */
|
/* Walk through ranges */
|
||||||
for (i = 0; i < num_ranges; i++) {
|
for (i = 0; i < num_ranges; i++) {
|
||||||
/* Count IPs in use */
|
for (; l != NULL && range_p->first_ip < l->ip; l = l->hh.prev)
|
||||||
|
/* rewind */ ;
|
||||||
|
if (l == NULL)
|
||||||
|
l = leases;
|
||||||
r_end = range_p->last_ip + 1;
|
r_end = range_p->last_ip + 1;
|
||||||
for (l = leases; l != NULL && l->ip < r_end; l = l->hh.next) {
|
for (; l != NULL && l->ip < r_end; l = l->hh.next) {
|
||||||
if (l->ip < range_p->first_ip) {
|
if (l->ip < range_p->first_ip) {
|
||||||
/* should not be necessary */
|
/* should not be necessary */
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue