Diff for /libaitio/example/Attic/rb.c between versions 1.2 and 1.2.30.1

version 1.2, 2011/06/07 11:49:39 version 1.2.30.1, 2012/08/15 08:45:21
Line 4 Line 4
 #include <unistd.h>  #include <unistd.h>
 #include <atree.h>  #include <atree.h>
 #include <sys/time.h>  #include <sys/time.h>
   #include <sys/queue.h>
   
 struct blah {  struct blah {
         int n;          int n;
         RB_ENTRY(blah) node;          RB_ENTRY(blah) node;
         SPLAY_ENTRY(blah) node1;          SPLAY_ENTRY(blah) node1;
         AVL_ENTRY(blah) node2;          AVL_ENTRY(blah) node2;
           SLIST_ENTRY(blah) node3;
           TAILQ_ENTRY(blah) node4;
 };  };
 RB_HEAD(rb_head, blah) rbh;  RB_HEAD(rb_head, blah) rbh;
 SPLAY_HEAD(sp_head, blah) sph;  SPLAY_HEAD(sp_head, blah) sph;
 AVL_HEAD(avl_head, blah) avlh;  AVL_HEAD(avl_head, blah) avlh;
   SLIST_HEAD(, blah) slh;
   TAILQ_HEAD(, blah) tqh;
   
 static int  static int
 rb_cmp(struct blah *a, struct blah *b)  rb_cmp(struct blah *a, struct blah *b)
Line 45  main() Line 50  main()
   
         RB_INIT(&rbh);          RB_INIT(&rbh);
         SPLAY_INIT(&sph);          SPLAY_INIT(&sph);
        AVL_INIT(&avlh, 0);        AVL_INIT(&avlh);
         SLIST_INIT(&slh);
         TAILQ_INIT(&tqh);
         srandom(getpid());          srandom(getpid());
   
         gettimeofday(&before, NULL);          gettimeofday(&before, NULL);
Line 80  main() Line 87  main()
         gettimeofday(&after, NULL);          gettimeofday(&after, NULL);
         printf("AVL::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6);          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");          printf("---\n");
   
         b2 = malloc(sizeof(struct blah));          b2 = malloc(sizeof(struct blah));
Line 106  main() Line 132  main()
         }          }
         gettimeofday(&after, NULL);          gettimeofday(&after, NULL);
         printf("RB::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6);          printf("RB::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6);
         free(b2);  
   
         printf("---\n");          printf("---\n");
   
         b2 = malloc(sizeof(struct blah));  
         gettimeofday(&before, NULL);          gettimeofday(&before, NULL);
         for (i = 0; i < 10000; i++) {          for (i = 0; i < 10000; i++) {
                 memset(b2, 0, sizeof(struct blah));                  memset(b2, 0, sizeof(struct blah));
Line 126  main() Line 150  main()
   
         printf("---\n");          printf("---\n");
   
           free(b2);
   
         gettimeofday(&before, NULL);          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) {          AVL_FOREACH_SAFE(b, avl_head, &avlh, b2) {
                 /*                  /*
                 printf("aaa %p[%d] %p[%d] --- ", b, b ? b->n : 0, b2, b2 ? b2->n : 0);                  printf("aaa %p[%d] %p[%d] --- ", b, b ? b->n : 0, b2, b2 ? b2->n : 0);
Line 138  main() Line 179  main()
         }          }
         gettimeofday(&after, NULL);          gettimeofday(&after, NULL);
         printf("AVL::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6);          printf("AVL::Time %f\n", (after.tv_sec - before.tv_sec) + (after.tv_usec - before.tv_usec) / 1e6);
   
         gettimeofday(&before, NULL);          gettimeofday(&before, NULL);
         for (b = SPLAY_MIN(sp_head, &sph); b; b = b2) {          for (b = SPLAY_MIN(sp_head, &sph); b; b = b2) {
                 b2 = SPLAY_NEXT(sp_head, &sph, b);                  b2 = SPLAY_NEXT(sp_head, &sph, b);

Removed from v.1.2  
changed lines
  Added in v.1.2.30.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>