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:
Sami Kerola 2012-11-07 23:36:57 +00:00
parent 7a86746710
commit 18f2835fd5

View file

@ -55,6 +55,8 @@ int prepare_data(void)
{
/* Sort leases */
HASH_SORT(leases, ip_sort);
/* Sort ranges */
qsort(ranges, (size_t) num_ranges, sizeof(struct range_t), &rangecomp);
return 0;
}
@ -62,17 +64,20 @@ int prepare_data(void)
int do_counting(void)
{
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;
range_p = ranges;
unsigned long r_end;
range_p = ranges;
/* Walk through ranges */
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;
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) {
/* should not be necessary */
continue;