Pprint模块在32位系统中与Django一起工作缓慢

cul*_*rón 3 python django performance profiling

我在使用Python 2.7的32位Ubuntu机器上使用Django.我的开发服务器一直很慢,大约需要15秒来渲染任何页面.我运行了一个cProfile测试,看看它的运行速度如此之慢.

似乎它是pprint模块.

这是我的统计数据:

ncalls       tottime percall cumtime percall filename:lineno(function)
272605/48718  24.238       0  49.213   0.001 pprint.py:247(_safe_repr)
Run Code Online (Sandbox Code Playgroud)

这是我的同事运行64位OS X:

14531/5334    1.016    0.000    2.199    0.000 pprint.py:247(_safe_repr)
Run Code Online (Sandbox Code Playgroud)

同时我必须关闭调试模式才能正常使用dev服务器.

这是分析脚本:

from cProfile import Profile
from django.test.client import Client
import Cookie
cl = Client()
cl.cookies = Cookie.SimpleCookie({'sessionid':'7344ebeba093b65c1d59a9d7583f60bc'})
p = Profile()
p.runctx("c.get('/welcome/')", globals={'c': cl}, locals={})
p.print_stats()
Run Code Online (Sandbox Code Playgroud)

(sessionid cookie用于显示您需要登录的页面.)

我不确定32位系统是主要原因.

主要问题是:为什么pprint._safe_repr在Python 2.7 32位和64位快速中如此之慢?如果我可以设置一些东西,使它快速.

jfs*_*jfs 5

为什么pprint._safe_repr在Python 2.7 32位中如此慢,在64位中快?

它在64位上并不快.你的同事得到的少得多ncalls.

您应该调查为什么单个GET导致如此大量的调用_safe_repr().