--- libaitio/example/Attic/rb.c 2011/06/07 11:49:39 1.2 +++ libaitio/example/Attic/rb.c 2012/08/15 08:45:21 1.2.30.1 @@ -4,16 +4,21 @@ #include #include #include +#include struct blah { int n; RB_ENTRY(blah) node; SPLAY_ENTRY(blah) node1; AVL_ENTRY(blah) node2; + SLIST_ENTRY(blah) node3; + TAILQ_ENTRY(blah) node4; }; RB_HEAD(rb_head, blah) rbh; SPLAY_HEAD(sp_head, blah) sph; AVL_HEAD(avl_head, blah) avlh; +SLIST_HEAD(, blah) slh; +TAILQ_HEAD(, blah) tqh; static int rb_cmp(struct blah *a, struct blah *b) @@ -45,7 +50,9 @@ main() RB_INIT(&rbh); SPLAY_INIT(&sph); - AVL_INIT(&avlh, 0); + AVL_INIT(&avlh); + SLIST_INIT(&slh); + TAILQ_INIT(&tqh); srandom(getpid()); gettimeofday(&before, NULL); @@ -80,6 +87,25 @@ main() gettimeofday(&after, NULL); printf("AVL::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6); + gettimeofday(&before, NULL); + for (i = 0; i < 1000000; i++) { + b = malloc(sizeof(struct blah)); + memset(b, 0, sizeof(struct blah)); + b->n = random(); + SLIST_INSERT_HEAD(&slh, b, node3); + } + gettimeofday(&after, NULL); + printf("SLIST::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6); + gettimeofday(&before, NULL); + for (i = 0; i < 1000000; i++) { + b = malloc(sizeof(struct blah)); + memset(b, 0, sizeof(struct blah)); + b->n = random(); + TAILQ_INSERT_HEAD(&tqh, b, node4); + } + gettimeofday(&after, NULL); + printf("TAILQ::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6); + printf("---\n"); b2 = malloc(sizeof(struct blah)); @@ -106,11 +132,9 @@ main() } gettimeofday(&after, NULL); printf("RB::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6); - free(b2); printf("---\n"); - b2 = malloc(sizeof(struct blah)); gettimeofday(&before, NULL); for (i = 0; i < 10000; i++) { memset(b2, 0, sizeof(struct blah)); @@ -126,7 +150,24 @@ main() printf("---\n"); + free(b2); + gettimeofday(&before, NULL); + while ((b = TAILQ_FIRST(&tqh))) { + TAILQ_REMOVE(&tqh, b, node4); + free(b); + } + gettimeofday(&after, NULL); + printf("TAILQ::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6); + gettimeofday(&before, NULL); + while ((b = SLIST_FIRST(&slh))) { + SLIST_REMOVE(&slh, b, blah, node3); + free(b); + } + gettimeofday(&after, NULL); + printf("SLIST::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6); + + gettimeofday(&before, NULL); AVL_FOREACH_SAFE(b, avl_head, &avlh, b2) { /* printf("aaa %p[%d] %p[%d] --- ", b, b ? b->n : 0, b2, b2 ? b2->n : 0); @@ -138,6 +179,7 @@ main() } gettimeofday(&after, NULL); printf("AVL::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6); + gettimeofday(&before, NULL); for (b = SPLAY_MIN(sp_head, &sph); b; b = b2) { b2 = SPLAY_NEXT(sp_head, &sph, b);