Created
November 8, 2015 13:32
-
-
Save benny-shotvibe/4a632a1be06ff06f0ab8 to your computer and use it in GitHub Desktop.
Django poor man's view performance measurement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make sure to set in settings.py: | |
# DEBUG = True | |
from django.db import connection | |
from django import db | |
import time | |
db.reset_queries() | |
start = time.time() | |
result = VIEW_FUNCTION_HERE(request) # !!!!! EDIT THIS LINE !!!!! | |
end = time.time() | |
total_queries_time = 0 | |
with open('/tmp/log.txt', 'w') as f: | |
for q in connection.queries: | |
total_queries_time += float(q['time']) + 0.0005 | |
f.write(q['time'] + ' ') | |
f.write(q['sql'] + '\n') | |
f.write('Queries time: ' + str(total_queries_time) + '\n') | |
f.write('Total time: ' + str(end - start) + '\n') | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment