我从django工具栏找到了debugsqlshell
,您可以使用它来运行它管理.py作为标准shell的替代,我想测试嵌套对象上查询的性能。在
我在每个查询上都可以看到certian输出,但是如何获得所有查询所用时间的总和呢?在
下面两种方法,我想比较一下。在
def stands(self):
stands = []
for stand in Stand.objects.all():
if stand.room.floor.building.fair.pk == self.pk:
stands.append(stand)
return stands
第二次使用prefetch_related
:
多亏了joel goldstick的提议,cProfile
我设法得到了一些确切的数字:
站起来():
11 685 649 function calls (10 532 897 primitive calls) in 9.861 seconds
stands3()使用prefetch_related
:
1 855 483 function calls (1 839 617 primitive calls) in 1.295 seconds
但是仍然从debugshell获得这些数字是很酷的,所以如果你知道怎么做就不用费心回答了。在
目前没有回答
相关问题 更多 >
编程相关推荐