Skip to content

Commit

Permalink
tests/test-cmap: Balance benchmarks between cmap and hmap.
Browse files Browse the repository at this point in the history
The test cases have been carefully crafted so that we do the same
amount of "overhead" operations in each case.  Earlier, with no
mutations, the number of random number generations was different for
hmap and cmap test cases.  hmap test was also missing an ignore() call.
Now the numbers look like this:

$ tests/ovstest test-cmap benchmark 2000000 8 0
Benchmarking with n=2000000, 8 threads, 0.00% mutations:
cmap insert:    597 ms
cmap iterate:    65 ms
cmap search:    299 ms
cmap destroy:   251 ms

hmap insert:    243 ms
hmap iterate:   201 ms
hmap search:    299 ms
hmap destroy:   202 ms

So it seems search on cmap can be as fast as on hmap in the
single-threaded case.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
  • Loading branch information
Jarno Rajahalme committed Oct 6, 2014
1 parent ee58b46 commit 44a4815
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions tests/test-cmap.c
Expand Up @@ -291,17 +291,23 @@ search_cmap(void *aux_)
struct cmap_aux *aux = aux_;
size_t i;

for (i = 0; i < n_elems; i++) {
struct element *e;
if (mutation_frac) {
for (i = 0; i < n_elems; i++) {
struct element *e;

if (random_uint32() < mutation_frac) {
ovs_mutex_lock(&aux->mutex);
e = find(aux->cmap, i);
if (e) {
cmap_remove(aux->cmap, &e->node, hash_int(e->value, 0));
if (random_uint32() < mutation_frac) {
ovs_mutex_lock(&aux->mutex);
e = find(aux->cmap, i);
if (e) {
cmap_remove(aux->cmap, &e->node, hash_int(e->value, 0));
}
ovs_mutex_unlock(&aux->mutex);
} else {
ignore(find(aux->cmap, i));
}
ovs_mutex_unlock(&aux->mutex);
} else {
}
} else {
for (i = 0; i < n_elems; i++) {
ignore(find(aux->cmap, i));
}
}
Expand Down Expand Up @@ -392,8 +398,8 @@ search_hmap(void *aux_)
struct hmap_aux *aux = aux_;
size_t i;

for (i = 0; i < n_elems; i++) {
if (mutation_frac) {
if (mutation_frac) {
for (i = 0; i < n_elems; i++) {
if (random_uint32() < mutation_frac) {
struct helement *e;

Expand All @@ -408,8 +414,10 @@ search_hmap(void *aux_)
ignore(hfind(aux->hmap, i));
fat_rwlock_unlock(&aux->fatlock);
}
} else {
hfind(aux->hmap, i);
}
} else {
for (i = 0; i < n_elems; i++) {
ignore(hfind(aux->hmap, i));
}
}
return NULL;
Expand Down

0 comments on commit 44a4815

Please sign in to comment.