Created
August 23, 2015 15:20
-
-
Save AlexandreProenca/1518f965c0c497652f2c to your computer and use it in GitHub Desktop.
Classe para formatar a saída dos resultados de performance do Django + DRF 3
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
# coding: utf-8 | |
class Formater: | |
cor = { | |
'ROXO' : '\033[95m', | |
'AZUL' : '\033[94m', | |
'VERDE' : '\033[92m', | |
'AMARELO' : '\033[93m', | |
'VERMELHO' : '\033[91m', | |
'BRANCO' : '\033[0m', | |
'BOLD' : '\033[1m', | |
'UNDERLINE' : '\033[4m' | |
} | |
def saida(self, db_time, serializer_time, request_response_time, api_view_time, render_time): | |
_total = float(db_time + serializer_time + request_response_time + api_view_time + render_time) | |
l = lambda x, y: 100 * x/y | |
sin = "=" * 50 | |
print ("") | |
print (self.cor['BRANCO']+sin) | |
print (self.cor['AMARELO']+"Consulta na base de dados | %.4fs --> %.1f%%" % (db_time, l(db_time, _total))) | |
print (self.cor['AZUL']+"Serialização | %.4fs --> %.1f%%" % (serializer_time, l(serializer_time, _total))) | |
print (self.cor['ROXO']+"Django request/response | %.4fs --> %.1f%%" % (request_response_time, l(request_response_time, _total))) | |
print (self.cor['VERDE']+"API view | %.4fs --> %.1f%%" % (api_view_time, l(api_view_time, _total))) | |
print (self.cor['BRANCO']+"Response renderização | %.4fs --> %.1f%%" % (render_time, l(render_time, _total))) | |
print (self.cor['VERMELHO']+"Total | %.4fs --> %.1f%%" % (_total, l(_total, _total))) | |
print (self.cor['BRANCO']+sin) | |
print ("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment