Speed-up lookup.
[apps/pfixtools.git] / common / tst-trie.c
index 990b151..739bd41 100644 (file)
@@ -54,8 +54,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();
@@ -130,6 +129,13 @@ int main(int argc, char *argv[])
     if (argc > 1) {
         trie = create_trie_from_file(argv[1]);
         trie_inspect(trie, false);
+        if (argc > 2) {
+            time_t now = time(NULL);
+            for (uint32_t i = 0 ; i < 1000000000 ; ++i) {
+                trie_lookup(trie, argv[2]);
+            }
+            printf("%lu lookups per second\n", 1000000000 / (time(NULL) - now));
+        }
         trie_delete(&trie);
     }
     return 0;