X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=ccan%2Fintmap%2Fbenchmark%2Fspeed.c;h=16eb40f355ae1ff7972a1f026912ce0c066fa198;hb=1966714494a5de39b2ee944fcc01f333c1741dbd;hp=7f59af29d93e4a96c69b27dc9812a30cc2fb99e9;hpb=82229812012a9cc9a4876b9542f5539ec99ece46;p=ccan diff --git a/ccan/intmap/benchmark/speed.c b/ccan/intmap/benchmark/speed.c index 7f59af29..16eb40f3 100644 --- a/ccan/intmap/benchmark/speed.c +++ b/ccan/intmap/benchmark/speed.c @@ -13,8 +13,8 @@ struct node { /* These point to strings or nodes. */ struct intmap child[2]; - /* The bit where these children differ (0 == lsb) */ - uint8_t bit_num; + /* Encoding both prefix and critbit: 1 is appended to prefix. */ + intmap_index_t prefix_and_critbit; }; static void update_span(const void *p, size_t s, uintptr_t *min, uintptr_t *max) @@ -61,6 +61,13 @@ static bool eqfn(const struct htable_elem *elem, const uint64_t index) } HTABLE_DEFINE_TYPE(struct htable_elem, keyof, hashfn, eqfn, hash); +static bool check_val(intmap_index_t i, uint64_t *v, uint64_t *expected) +{ + if (v != expected) + abort(); + return true; +} + int main(int argc, char *argv[]) { uint64_t i, total = 0, seed, *v; @@ -127,6 +134,12 @@ int main(int argc, char *argv[]) printf("%zu,critbit iteration (nsec),%"PRIu64"\n", max, time_to_nsec(time_divide(time_between(end, start), max))); + start = time_now(); + uintmap_iterate(&map, check_val, &i); + end = time_now(); + printf("%zu,critbit callback iteration (nsec),%"PRIu64"\n", max, + time_to_nsec(time_divide(time_between(end, start), max))); + span_min = -1ULL; span_max = 0; getspan(uintmap_unwrap_(&map), &span_min, &span_max); @@ -157,6 +170,12 @@ int main(int argc, char *argv[]) printf("%zu,critbit consecutive iteration (nsec),%"PRIu64"\n", max, time_to_nsec(time_divide(time_between(end, start), max))); + start = time_now(); + uintmap_iterate(&map, check_val, &i); + end = time_now(); + printf("%zu,critbit consecutive callback iteration (nsec),%"PRIu64"\n", max, + time_to_nsec(time_divide(time_between(end, start), max))); + sipseed.u.u64[0] = isaac64_next_uint64(&isaac); sipseed.u.u64[1] = isaac64_next_uint64(&isaac);