forked from loklak/loklak_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile_queries.py
41 lines (34 loc) · 1.29 KB
/
profile_queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import os
import time
import json
try:
import requests
except ImportError:
print('Profiling script requires requests package. \n'
'You can install it by running "pip install requests"')
exit()
API_BASE_URL = 'http://127.0.0.1:9000/api/'
# If user in bin directory set correct path to quires
if os.getcwd().endswith('bin'):
queries_folder = os.getcwd().rstrip('bin') + 'test/queries'
else:
queries_folder = os.getcwd() + '/test/queries'
results = []
test_queries = []
for file_name in os.listdir(queries_folder):
if file_name.endswith('.txt') and file_name != 'README.txt':
for query in open('{}/{}'.format(queries_folder, file_name)).readlines():
test_queries.append(query.rstrip())
print('Start profiling {} queries'.format(len(test_queries)))
for query in test_queries:
time_start = time.time()
url = API_BASE_URL + 'search.json?source=cache&q={}'.format(query)
result = json.loads(requests.get(url).text)
assert 'statuses' in result
time_finish = time.time()
results.append(time_finish - time_start)
print('Profiling finished.')
print('Average time: {} seconds'.format(sum(results) / len(results)))
print('Minimal time: {} seconds'.format(min(results)))
print('Maximal time: {} seconds'.format(max(results)))