]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
database: Log how long it took to retrieve an AS
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Dec 2017 16:58:16 +0000 (16:58 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 Dec 2017 16:58:16 +0000 (16:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c
src/test-as.c

index 3a4f8b8bb13a81dd4099bdb78b3b89edd6b9b173..e5460da3bb25bc5b49f1d2af9fc8f1f3985d7cf6 100644 (file)
@@ -272,6 +272,9 @@ LOC_EXPORT int loc_database_get_as(struct loc_database* db, struct loc_as** as,
        off_t lo = 0;
        off_t hi = db->as_count - 1;
 
+       // Save start time
+       clock_t start = clock();
+
        while (lo <= hi) {
                off_t i = (lo + hi) / 2;
 
@@ -282,8 +285,15 @@ LOC_EXPORT int loc_database_get_as(struct loc_database* db, struct loc_as** as,
 
                // Check if this is a match
                uint32_t as_number = loc_as_get_number(*as);
-               if (as_number == number)
+               if (as_number == number) {
+                       clock_t end = clock();
+
+                       // Log how fast this has been
+                       DEBUG(db->ctx, "Found AS%u in %.8fs\n", as_number,
+                               (double)(end - start) / CLOCKS_PER_SEC);
+
                        return 0;
+               }
 
                // If it wasn't, we release the AS and
                // adjust our search pointers
@@ -298,5 +308,5 @@ LOC_EXPORT int loc_database_get_as(struct loc_database* db, struct loc_as** as,
        // Nothing found
        *as = NULL;
 
-       return 0;
+       return 1;
 }
index 48c5ab727582c564271de9c8a0bba22d29e7ac01..0c4d391e78e56fb7745e785a89e57bdaf3e61b74 100644 (file)
@@ -22,7 +22,7 @@
 #include <loc/writer.h>
 #include "database.h"
 
-#define TEST_AS_COUNT 100
+#define TEST_AS_COUNT 5000
 
 int main(int argc, char** argv) {
        int err;
@@ -85,10 +85,14 @@ int main(int argc, char** argv) {
        }
 
        struct loc_as* as;
-       err = loc_database_get_as(db, &as, 99);
-       if (err) {
-               fprintf(stderr, "Could not find AS99\n");
-               exit(EXIT_FAILURE);
+       for (unsigned int i = 1; i <= 10; i++) {
+               err = loc_database_get_as(db, &as, i);
+               if (err) {
+                       fprintf(stderr, "Could not find AS%d\n", i);
+                       exit(EXIT_FAILURE);
+               }
+
+               loc_as_unref(as);
        }
 
        loc_database_unref(db);