Add likely/unlikely macros.
[apps/pfixtools.git] / common / tst-trie.c
index 78977a8..31d6c1b 100644 (file)
@@ -33,6 +33,8 @@
  * Copyright © 2008 Florent Bruneau
  */
 
+#include <time.h>
+#include <sys/time.h>
 #include "common.h"
 #include "str.h"
 #include "trie.h"
@@ -54,8 +56,7 @@ static trie_t *create_trie_from_file(const char *file)
         --end;
     }
     if (end != map.end) {
-        syslog(LOG_WARNING, "file %s miss a final \\n, ignoring last line",
-               file);
+        warn("file %s miss a final \\n, ignoring last line", file);
     }
 
     db = trie_new();
@@ -129,7 +130,20 @@ int main(int argc, char *argv[])
      */
     if (argc > 1) {
         trie = create_trie_from_file(argv[1]);
-        trie_inspect(trie, true);
+        trie_inspect(trie, false);
+        if (argc > 2) {
+            const uint32_t how_many = 2 * 1000 * 1000;
+            struct timeval start, end;
+            double diff;
+
+            gettimeofday(&start, NULL);
+            for (uint32_t i = 0 ; i < how_many ; ++i) {
+                trie_lookup(trie, argv[2]);
+            }
+            gettimeofday(&end, NULL);
+            diff = (end.tv_sec - start.tv_sec) + (double)(end.tv_usec - start.tv_usec) / 10e6;
+            printf("%u lookups per second\n", (int)(how_many / diff));
+        }
         trie_delete(&trie);
     }
     return 0;