def run_profiling(self, num_loops, num_neighbors, age_proximity):
"""Executes the k_nearest_neighbors algorithm for num_loops times and returns the average running time
Args:
num_loops: number of loops for which we query the server
num_neighbors: number of neighbors to query for
age_proximity: maximum difference between a candidate neighbor's age and the user
Returns:
"""
print('profiling over ', num_loops, ' times')
random_latitudes = random.uniform(-90, 90, num_loops)
random_longitudes = random.uniform(-180, 180, num_loops)
time_list = []
for i in tqdm(range(len(random_latitudes))):
start_time = time.clock()
kd_store.k_nearest_neighbors({'name': 'bla bla', 'age': 23, 'latitude': random_latitudes[i] / 2,
'longitude': random_longitudes[i]}, num_neighbors, age_proximity)
end_time = time.clock()
time_list.append(end_time - start_time)
# get the timing statistics
stats_desc = stats.describe(time_list)
frac_times_exceeded = len(np.where(np.array(time_list) >= 1)[0]) / len(time_list)
print('\nfraction of times with delay > 1 is: ', frac_times_exceeded, '\n')
print('\nStats:\n', stats_desc)
return stats_desc
评论列表
文章目录