Commit 977bd8d5 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

lib/rbtree_test.c: add (inorder) traversal test

This adds a second test for regular rb-tree testing in that there is no
need to repeat it for the augmented flavor.

Link: http://lkml.kernel.org/r/20170719014603.19029-6-dave@stgolabs.netSigned-off-by: default avatarDavidlohr Bueso <dbueso@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 223f8911
...@@ -183,6 +183,7 @@ static int __init rbtree_test_init(void) ...@@ -183,6 +183,7 @@ static int __init rbtree_test_init(void)
{ {
int i, j; int i, j;
cycles_t time1, time2, time; cycles_t time1, time2, time;
struct rb_node *node;
nodes = kmalloc(nnodes * sizeof(*nodes), GFP_KERNEL); nodes = kmalloc(nnodes * sizeof(*nodes), GFP_KERNEL);
if (!nodes) if (!nodes)
...@@ -206,8 +207,28 @@ static int __init rbtree_test_init(void) ...@@ -206,8 +207,28 @@ static int __init rbtree_test_init(void)
time = time2 - time1; time = time2 - time1;
time = div_u64(time, perf_loops); time = div_u64(time, perf_loops);
printk(" -> %llu cycles\n", (unsigned long long)time); printk(" -> test 1 (latency of nnodes insert+delete): %llu cycles\n", (unsigned long long)time);
for (i = 0; i < nnodes; i++)
insert(nodes + i, &root);
time1 = get_cycles();
for (i = 0; i < perf_loops; i++) {
for (node = rb_first(&root); node; node = rb_next(node))
;
}
time2 = get_cycles();
time = time2 - time1;
time = div_u64(time, perf_loops);
printk(" -> test 2 (latency of inorder traversal): %llu cycles\n", (unsigned long long)time);
for (i = 0; i < nnodes; i++)
erase(nodes + i, &root);
/* run checks */
for (i = 0; i < check_loops; i++) { for (i = 0; i < check_loops; i++) {
init(); init();
for (j = 0; j < nnodes; j++) { for (j = 0; j < nnodes; j++) {
...@@ -238,7 +259,7 @@ static int __init rbtree_test_init(void) ...@@ -238,7 +259,7 @@ static int __init rbtree_test_init(void)
time = time2 - time1; time = time2 - time1;
time = div_u64(time, perf_loops); time = div_u64(time, perf_loops);
printk(" -> %llu cycles\n", (unsigned long long)time); printk(" -> test 1 (latency of nnodes insert+delete): %llu cycles\n", (unsigned long long)time);
for (i = 0; i < check_loops; i++) { for (i = 0; i < check_loops; i++) {
init(); init();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment