benchmark: output result to JSON
This commit is contained in:
parent
f588355118
commit
3c1d4072a8
30
benchmark
30
benchmark
|
@ -2,6 +2,10 @@
|
|||
|
||||
import os.path
|
||||
import time
|
||||
import json
|
||||
|
||||
import numpy
|
||||
import random
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "docbow_project.settings")
|
||||
|
||||
|
@ -11,15 +15,28 @@ from django.test.client import RequestFactory
|
|||
from docbow_project.docbow.models import FileType
|
||||
from docbow_project.docbow.views import inbox_view, outbox_view, send_file
|
||||
|
||||
def stat(seq):
|
||||
return {
|
||||
'min': min(seq),
|
||||
'max': max(seq),
|
||||
'mean': numpy.mean(seq),
|
||||
'median': numpy.median(seq),
|
||||
'std': numpy.std(seq),
|
||||
}
|
||||
|
||||
rf = RequestFactory()
|
||||
paths = [('/inbox/', inbox_view, {}), ('/outbox/', outbox_view, {})]
|
||||
for file_type in FileType.objects.all():
|
||||
filetypes = list(FileType.objects.all())
|
||||
random.shuffle(filetypes)
|
||||
for file_type in filetypes[:10]:
|
||||
paths.append(('/inbox/%s/' % file_type.id, send_file, {'file_type_id': file_type.id}))
|
||||
data = []
|
||||
for path, view, kwargs in paths:
|
||||
get_request = rf.get(path)
|
||||
get_request.session = {}
|
||||
print 'Testing view', path, 'for all users:'
|
||||
print
|
||||
seq = []
|
||||
for user in User.objects.all():
|
||||
get_request.user = user
|
||||
now = time.time()
|
||||
|
@ -28,8 +45,13 @@ for path, view, kwargs in paths:
|
|||
response.render()
|
||||
str(response)
|
||||
duration = time.time()-now
|
||||
if duration > 2:
|
||||
print user, ':', duration, 's'
|
||||
|
||||
seq.append(duration*1000)
|
||||
data.append(stat(seq))
|
||||
data[-1]['path'] = path
|
||||
|
||||
with file('vix.js', 'w') as f:
|
||||
f.write('''var vix =
|
||||
''')
|
||||
f.write(json.dumps(data, indent=4))
|
||||
f.write(';')
|
||||
|
||||
|
|
Loading…
Reference in New Issue