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;
// 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
// Nothing found
*as = NULL;
- return 0;
+ return 1;
}
#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;
}
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);