Skip to content

Commit

Permalink
Merge pull request erikbern#19 from maau/query-timing
Browse files Browse the repository at this point in the history
Only measure the time of the actual lookup.
  • Loading branch information
maumueller authored and GitHub Enterprise committed Mar 21, 2017
2 parents 9d8ea04 + 839aa6c commit 5b3c969
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 19 additions & 2 deletions ann_benchmarks/algorithms/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, args, encoder, params, prepared = False):
self.query = self.__query_normal
else:
self.query = self.__query_prepared
self._result_count = None

def supports_prepared_queries(self):
return self._prepared
Expand Down Expand Up @@ -94,7 +95,7 @@ def __handle_query_response(self):
return results
else:
assert status[0] == "fail", """\
searching for encoded query point '%s' neither succeeded nor failed""" % d
query neither succeeded nor failed"""
return []

def prepare_query(self, v, n):
Expand All @@ -105,7 +106,23 @@ def prepare_query(self, v, n):

def run_prepared_query(self):
self.__write("query")
return self.__handle_query_response()
status = self.__line()
if status[0] == "ok":
self._result_count = int(status[1])
else:
assert status[0] == "fail", """\
query neither succeeded nor failed"""
self._result_count = 0

def get_prepared_query_results(self):
results = []
i = 0
while i < self._result_count:
line = self.__line()
results.append(int(line[0]))
i += 1
self._result_count = 0
return results

def use_threads(self):
return False
Expand Down
3 changes: 2 additions & 1 deletion ann_benchmarks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def single_query(t):
if prepared_queries:
algo.prepare_query(v, 10)
start = time.time()
found = algo.run_prepared_query()
algo.run_prepared_query()
total = (time.time() - start)
found = algo.get_prepared_query_results()
else:
start = time.time()
found = algo.query(v, 10)
Expand Down

0 comments on commit 5b3c969

Please sign in to comment.